diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 1068756a..dba7f345 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -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" diff --git a/cmd/pull.go b/cmd/pull.go index aa3ad116..2376003a 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -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() diff --git a/core/yaml_test.go b/core/yaml_test.go new file mode 100644 index 00000000..96295d9f --- /dev/null +++ b/core/yaml_test.go @@ -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) + }) + } +}