Skip to content

Commit 1b24c6a

Browse files
add test
1 parent d75b76a commit 1b24c6a

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

cmd/analyze.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
312312
// Use the configuration system to get the tools config directory
313313
toolsConfigDir := config.Config.ToolsConfigDirectory()
314314
toolConfigPath := filepath.Join(toolsConfigDir, configFileName)
315+
315316
// Check if the config file exists
316317
if _, err := os.Stat(toolConfigPath); os.IsNotExist(err) {
317318
// Config file does not exist - create it if we have the means to do so

cmd/configsetup/repository_config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ func createToolConfigurationFiles(tools []domain.Tool, flags domain.InitFlags) e
9393
// CreateToolConfigurationFile creates a configuration file for a single tool
9494
func CreateToolConfigurationFile(toolName string, flags domain.InitFlags) error {
9595
// Find the tool UUID by tool name
96-
fmt.Printf("Creating configuration file for tool %s\n", toolName)
9796
toolUUID := getToolUUIDByName(toolName)
9897
if toolUUID == "" {
9998
return fmt.Errorf("tool '%s' not found in supported tools", toolName)

tools/lizard/lizardRunner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s
2121
configFile, exists := tools.ConfigFileExists(config.Config, "lizard.yaml")
2222
var patterns []domain.PatternDefinition
2323
var errConfigs error
24+
2425
if exists {
2526
// Configuration exists, read from file
2627
patterns, errConfigs = ReadConfig(configFile)
@@ -34,6 +35,7 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s
3435
return fmt.Errorf("failed to fetch default patterns: %v", errConfigs)
3536
}
3637
}
38+
3739
if len(patterns) == 0 {
3840
return fmt.Errorf("no valid patterns found in configuration")
3941
}

tools/runnerUtils_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ func TestConfigFileExistsInToolsConfigDirectory(t *testing.T) {
3535
"Config path should be correctly formed relative path")
3636
}
3737

38+
func TestConfigFilePrefersToolsConfigDirectory(t *testing.T) {
39+
// Create a test directory structure
40+
tempDir := t.TempDir()
41+
repoDir := filepath.Join(tempDir, "src")
42+
repositoryCache := filepath.Join(repoDir, ".codacy")
43+
44+
// Create configuration
45+
config := *config.NewConfigType(repoDir, repositoryCache, "unused-global-cache")
46+
47+
// Create .codacy/tools-configs directory
48+
configDir := filepath.Join(repoDir, ".codacy", "tools-configs")
49+
err := os.MkdirAll(configDir, 0755)
50+
assert.NoError(t, err, "Failed to create test directory structure")
51+
52+
// Create a test config file in both locations
53+
generatedConfigFile := filepath.Join(configDir, "some-config.yaml")
54+
existingConfigFile := filepath.Join(repoDir, "some-config.yaml")
55+
56+
err = os.WriteFile(generatedConfigFile, []byte("tools config content"), 0644)
57+
assert.NoError(t, err, "Failed to create test config file in tools config directory")
58+
59+
err = os.WriteFile(existingConfigFile, []byte("repository config content"), 0644)
60+
assert.NoError(t, err, "Failed to create test config file in repository directory")
61+
62+
// Test case: Config file in tools config directory is preferred
63+
configPath, exists := ConfigFileExists(config, "some-config.yaml")
64+
assert.True(t, exists, "Config file should exist")
65+
assert.Equal(t, filepath.Join(config.ToolsConfigDirectory(), "some-config.yaml"), configPath,
66+
"Config path should prefer tools config directory")
67+
}
68+
3869
func TestConfigFileExistsInRepositoryDirectory(t *testing.T) {
3970
// Create a test directory structure
4071
tempDir := t.TempDir()

0 commit comments

Comments
 (0)