Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont pull in native mode #248

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ func TestContributorsCommand(t *testing.T) {
}
}

func TestPullInNative(t *testing.T) {
projectPath := createProject(t, "qodana_scan_python_native")
yamlFile := filepath.Join(projectPath, "qodana.yaml")
_ = os.WriteFile(yamlFile, []byte("ide: QDPY"), 0o755)
out := bytes.NewBufferString("")
command := newPullCommand()
command.SetOut(out)
command.SetArgs([]string{"-i", projectPath})
err := command.Execute()
if err != nil {
t.Fatal(err)
}
}

func TestAllCommandsWithContainer(t *testing.T) {
linter := "registry.jetbrains.team/p/sa/containers/qodana-dotnet:latest"

Expand Down
16 changes: 9 additions & 7 deletions cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ func newPullCommand() *cobra.Command {
Use: "pull",
Short: "Pull latest version of linter",
Long: `An alternative to pull an image.`,
PreRun: func(cmd *cobra.Command, args []string) {
core.PrepareContainerEnvSettings()
},
Run: func(cmd *cobra.Command, args []string) {
options.FetchAnalyzerSettings()
containerClient, err := client.NewClientWithOpts()
if err != nil {
log.Fatal("couldn't connect to container engine ", err)
if options.Ide != "" {
log.Println("Native mode is used, skipping pull")
} else {
core.PrepareContainerEnvSettings()
containerClient, err := client.NewClientWithOpts()
if err != nil {
log.Fatal("couldn't connect to container engine ", err)
}
core.PullImage(containerClient, options.Linter)
}
core.PullImage(containerClient, options.Linter)
},
}
flags := cmd.Flags()
Expand Down
94 changes: 94 additions & 0 deletions core/yaml_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package core

import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"os"
"path/filepath"
"testing"
)

func setupTestFile(fileName string, content string) {
tempDir := os.TempDir()
tempFile := filepath.Join(tempDir, fileName)

// create a test file with provided content and filename
file, err := os.Create(tempFile)
if err != nil {
log.Fatal(err)
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Fatal(err)
}
}(file)
_, err = file.WriteString(content)
if err != nil {
log.Fatal(err)
}
err = file.Sync()
if err != nil {
log.Fatal(err)
}
}

func TestLoadQodanaYaml(t *testing.T) {
testCases := []struct {
description string
setup func(name string)
project string
filename string
expected *QodanaYaml
}{
{
description: "file exists but is empty",
setup: func(name string) {
setupTestFile(name, "")
},
project: os.TempDir(),
filename: "empty.yaml",
expected: &QodanaYaml{},
},
{
description: "file exists with valid content",
setup: func(name string) {
content := `version: 1.0`
setupTestFile(name, content)
},
project: os.TempDir(),
filename: "valid.yaml",
expected: &QodanaYaml{
Version: "1.0",
},
},
{
description: "file exists with .net section",
setup: func(name string) {
content := `version: 1.0
dotnet:
project: test.csproj
frameworks: "!netstandard2.0;!netstandard2.1"`
setupTestFile(name, content)
},
project: os.TempDir(),
filename: "dotnet.yaml",
expected: &QodanaYaml{
Version: "1.0",
DotNet: DotNet{
Project: "test.csproj",
Frameworks: "!netstandard2.0;!netstandard2.1",
},
},
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
tc.setup(tc.filename)
actual := LoadQodanaYaml(tc.project, tc.filename)
_ = os.Remove(filepath.Join(tc.project, tc.filename))
assert.Equal(t, tc.expected, actual)
})
}
}
Loading