|
| 1 | +package tools |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | +) |
| 10 | + |
| 11 | +func TestConfigFileExists(t *testing.T) { |
| 12 | + // Create a test directory structure |
| 13 | + tempDir := t.TempDir() |
| 14 | + |
| 15 | + // Create .codacy/tools-configs directory |
| 16 | + configDir := filepath.Join(tempDir, ".codacy", "tools-configs") |
| 17 | + |
| 18 | + err := os.MkdirAll(configDir, 0755) |
| 19 | + assert.NoError(t, err, "Failed to create test directory structure") |
| 20 | + |
| 21 | + // Create a test config file |
| 22 | + testConfigFile := filepath.Join(configDir, "test-config.yaml") |
| 23 | + err = os.WriteFile(testConfigFile, []byte("test content"), 0644) |
| 24 | + assert.NoError(t, err, "Failed to create test config file") |
| 25 | + |
| 26 | + // Test case 1: Config file exists |
| 27 | + configPath, exists := ConfigFileExists(tempDir, "test-config.yaml") |
| 28 | + assert.True(t, exists, "Config file should exist") |
| 29 | + assert.Equal(t, filepath.Join(".codacy", "tools-configs", "test-config.yaml"), configPath, |
| 30 | + "Config path should be correctly formed relative path") |
| 31 | + |
| 32 | + // Test case 2: Config file doesn't exist |
| 33 | + configPath, exists = ConfigFileExists(tempDir, "non-existent-config.yaml") |
| 34 | + assert.False(t, exists, "Config file should not exist") |
| 35 | + assert.Equal(t, "", configPath, "Config path should be empty for non-existent file") |
| 36 | +} |
0 commit comments