Skip to content

Commit

Permalink
🧪 Fix all tests, add platform JARs
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jan 30, 2024
1 parent 5c9a353 commit 1a0a7b4
Show file tree
Hide file tree
Showing 37 changed files with 737 additions and 748 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.jar filter=lfs diff=lfs merge=lfs -text
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- run: rm -rf linter
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
golangci_lint_flags: --skip-dirs linter/tooling/

test:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -46,6 +49,8 @@ jobs:
registry: registry.jetbrains.team
username: ${{ secrets.SPACE_USERNAME }}
password: ${{ secrets.SPACE_PASSWORD }}
- run: rm -rf linter # temporary workaround
shell: bash
- name: Run tests (with coverage)
if: ${{ matrix.os != 'windows-latest' }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check PR Commits Against Main Branch
name: Release branch

on:
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,goland,go
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,goland,go
.qodana
linter/tooling/clt.zip
qodana
### Go ###
# Binaries for programs and plugins
*.exe
Expand Down
1 change: 0 additions & 1 deletion cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

func TestGetProjectByBadToken(t *testing.T) {
t.Skip() // Until qodana.cloud response is fixed
client := NewQdClient("https://www.jetbrains.com")
result := client.getProject()
switch v := result.(type) {
Expand Down
20 changes: 15 additions & 5 deletions cloud/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const (

qodanaLicenseRequestCooldown = 60

qodanaLicenseUri = "/v1/linters/license-key"
qodanaLicenseUri = "/v1/linters/license-key"
QodanaToken = "QODANA_TOKEN"
QodanaLicenseOnlyToken = "QODANA_LICENSE_ONLY_TOKEN"
)

var TokenDeclinedError = errors.New("token was declined by Qodana Cloud server")
Expand Down Expand Up @@ -202,10 +204,18 @@ func GetEnvWithDefaultInt(env string, defaultValue int) int {
return result
}

func SetupLicenseToken(token string, licenseOnly bool) {
Token = LicenseToken{
Token: token,
LicenseOnly: licenseOnly,
func SetupLicenseToken(token string) {
licenseOnlyToken := os.Getenv(QodanaLicenseOnlyToken)
if token == "" && licenseOnlyToken != "" {
Token = LicenseToken{
Token: licenseOnlyToken,
LicenseOnly: true,
}
} else {
Token = LicenseToken{
Token: token,
LicenseOnly: false,
}
}
}

Expand Down
80 changes: 80 additions & 0 deletions cloud/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,86 @@ import (
"time"
)

func TestSetupLicenseToken(t *testing.T) {
for _, testData := range []struct {
name string
token string
loToken string
resToken string
sendFus bool
sendReport bool
}{
{
name: "no key",
token: "",
loToken: "",
resToken: "",
sendFus: true,
sendReport: false,
},
{
name: "with token",
token: "a",
loToken: "",
resToken: "a",
sendFus: true,
sendReport: true,
},
{
name: "with license only token",
token: "",
loToken: "b",
resToken: "b",
sendFus: false,
sendReport: false,
},
{
name: "both tokens",
token: "a",
loToken: "b",
resToken: "a",
sendFus: true,
sendReport: true,
},
} {
t.Run(testData.name, func(t *testing.T) {
err := os.Setenv(QodanaLicenseOnlyToken, testData.loToken)
if err != nil {
t.Fatal(err)
}
err = os.Setenv(QodanaToken, testData.token)
if err != nil {
t.Fatal(err)
}
SetupLicenseToken(testData.token)

if Token.Token != testData.resToken {
t.Errorf("expected token to be '%s' got '%s'", testData.resToken, Token.Token)
}

sendFUS := Token.IsAllowedToSendFUS()
if sendFUS != testData.sendFus {
t.Errorf("expected allow FUS to be '%t' got '%t'", testData.sendFus, sendFUS)
}

toSendReports := Token.IsAllowedToSendReports()
if toSendReports != testData.sendReport {
t.Errorf("expected allow send report to be '%t' got '%t'", testData.sendReport, toSendReports)
}

err = os.Unsetenv(QodanaLicenseOnlyToken)
if err != nil {
t.Fatal(err)
}

err = os.Unsetenv(QodanaToken)
if err != nil {
t.Fatal(err)
}
})
}
}

func TestRequestLicenseData(t *testing.T) {
expectedLicense := "license data"
rightToken := "token data"
Expand Down
17 changes: 9 additions & 8 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ But you can always override qodana.yaml options with the following command-line
ctx := cmd.Context()
checkProjectDir(options.ProjectDir)
options.FetchAnalyzerSettings()
exitCode := core.RunAnalysis(ctx, &core.QodanaOptions{QodanaOptions: options})
qodanaOptions := core.QodanaOptions{QodanaOptions: options}
exitCode := core.RunAnalysis(ctx, &qodanaOptions)

checkExitCode(exitCode, options.ResultsDir, options)
checkExitCode(exitCode, options.ResultsDir, &qodanaOptions)
core.ReadSarif(filepath.Join(options.ResultsDir, platform.QodanaSarifName), options.PrintProblems)
if platform.IsInteractive() {
options.ShowReport = platform.AskUserConfirm("Do you want to open the latest report")
Expand All @@ -69,7 +70,7 @@ But you can always override qodana.yaml options with the following command-line
)
}

if exitCode == core.QodanaFailThresholdExitCode {
if exitCode == platform.QodanaFailThresholdExitCode {
platform.EmptyMessage()
platform.ErrorMessage("The number of problems exceeds the fail threshold")
os.Exit(exitCode)
Expand Down Expand Up @@ -101,20 +102,20 @@ func checkProjectDir(projectDir string) {
}

func checkExitCode(exitCode int, resultsDir string, options *core.QodanaOptions) {
if exitCode == core.QodanaEapLicenseExpiredExitCode && platform.IsInteractive() {
if exitCode == platform.QodanaEapLicenseExpiredExitCode && platform.IsInteractive() {
platform.EmptyMessage()
platform.ErrorMessage(
"Your license expired: update your license or token. If you are using EAP, make sure you are using the latest CLI version and update to the latest linter by running %s ",
platform.PrimaryBold("qodana init"),
)
os.Exit(exitCode)
} else if exitCode == core.QodanaTimeoutExitCodePlaceholder {
core.ErrorMessage("Qodana analysis reached timeout %s", options.GetAnalysisTimeout())
} else if exitCode == platform.QodanaTimeoutExitCodePlaceholder {
platform.ErrorMessage("Qodana analysis reached timeout %s", options.GetAnalysisTimeout())
os.Exit(options.AnalysisTimeoutExitCode)
} else if exitCode != core.QodanaSuccessExitCode && exitCode != core.QodanaFailThresholdExitCode {
} else if exitCode != platform.QodanaSuccessExitCode && exitCode != platform.QodanaFailThresholdExitCode {
platform.ErrorMessage("Qodana exited with code %d", exitCode)
platform.WarningMessage("Check ./logs/ in the results directory for more information")
if exitCode == core.QodanaOutOfMemoryExitCode {
if exitCode == platform.QodanaOutOfMemoryExitCode {
core.CheckContainerEngineMemory()
} else if platform.AskUserConfirm(fmt.Sprintf("Do you want to open %s", resultsDir)) {
err := core.OpenDir(resultsDir)
Expand Down
104 changes: 0 additions & 104 deletions core/cmd.go

This file was deleted.

13 changes: 1 addition & 12 deletions core/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ import (
)

const (
// QodanaSuccessExitCode is Qodana exit code when the analysis is successfully completed.
QodanaSuccessExitCode = 0
// QodanaFailThresholdExitCode same as QodanaSuccessExitCode, but the threshold is set and exceeded.
QodanaFailThresholdExitCode = 255
// QodanaOutOfMemoryExitCode reports an interrupted process, sometimes because of an OOM.
QodanaOutOfMemoryExitCode = 137
// QodanaEapLicenseExpiredExitCode reports an expired license.
QodanaEapLicenseExpiredExitCode = 7
// QodanaTimeoutExitCodePlaceholder is not a real exit code (it is not obtained from IDE process! and not returned from CLI)
// Placeholder used to identify the case when the analysis reached timeout
QodanaTimeoutExitCodePlaceholder = 1000
// officialImagePrefix is the prefix of official Qodana images.
officialImagePrefix = "jetbrains/qodana"
dockerSpecialCharsLength = 8
Expand Down Expand Up @@ -291,7 +280,7 @@ func CheckContainerEngineMemory() {

// getDockerOptions returns qodana docker container options.
func getDockerOptions(opts *QodanaOptions) *types.ContainerCreateConfig {
cmdOpts := getIdeArgs(opts)
cmdOpts := GetIdeArgs(opts)
platform.ExtractQodanaEnvironment(opts.Setenv)
cachePath, err := filepath.Abs(opts.CacheDir)
if err != nil {
Expand Down
Loading

0 comments on commit 1a0a7b4

Please sign in to comment.