Skip to content

Commit 4962c8b

Browse files
fix test
1 parent faa791f commit 4962c8b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

cmd/init_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package cmd
22

33
import (
44
"codacy/cli-v2/config"
5+
"codacy/cli-v2/constants"
56
"codacy/cli-v2/domain"
6-
"codacy/cli-v2/utils"
77
"os"
88
"path/filepath"
99
"testing"
@@ -127,7 +127,7 @@ func TestCleanConfigDirectory(t *testing.T) {
127127

128128
for _, file := range testFiles {
129129
filePath := filepath.Join(tempDir, file)
130-
err := os.WriteFile(filePath, []byte("test content"), utils.DefaultFilePerms)
130+
err := os.WriteFile(filePath, []byte("test content"), constants.DefaultFilePerms)
131131
assert.NoError(t, err, "Failed to create test file: %s", filePath)
132132
}
133133

@@ -153,6 +153,13 @@ func TestInitCommand_LanguageDetection(t *testing.T) {
153153
assert.NoError(t, err, "Failed to get current working directory")
154154
defer os.Chdir(originalWD)
155155

156+
// Change to the temp directory
157+
err = os.Chdir(tempDir)
158+
assert.NoError(t, err)
159+
160+
// Set up config with the correct paths
161+
config.Config = *config.NewConfigType(tempDir, filepath.Join(tempDir, ".codacy"), filepath.Join(tempDir, ".cache", "codacy"))
162+
156163
// Create test files for different languages
157164
testFiles := map[string]string{
158165
"src/main.go": "package main",
@@ -172,21 +179,17 @@ func TestInitCommand_LanguageDetection(t *testing.T) {
172179
// Create the files in the temporary directory
173180
for path, content := range testFiles {
174181
fullPath := filepath.Join(tempDir, path)
175-
err := os.MkdirAll(filepath.Dir(fullPath), 0755)
182+
err := os.MkdirAll(filepath.Dir(fullPath), constants.DefaultDirPerms)
176183
assert.NoError(t, err)
177-
err = os.WriteFile(fullPath, []byte(content), 0644)
184+
err = os.WriteFile(fullPath, []byte(content), constants.DefaultFilePerms)
178185
assert.NoError(t, err)
179186
}
180187

181-
// Change to the temp directory
182-
err = os.Chdir(tempDir)
183-
assert.NoError(t, err)
184-
185188
// Create necessary directories
186189
err = config.Config.CreateLocalCodacyDir()
187190
assert.NoError(t, err)
188191
toolsConfigDir := config.Config.ToolsConfigDirectory()
189-
err = os.MkdirAll(toolsConfigDir, utils.DefaultFilePerms)
192+
err = os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms)
190193
assert.NoError(t, err)
191194

192195
// Reset initFlags to simulate local mode
@@ -241,11 +244,14 @@ func TestInitCommand_NoLanguagesDetected(t *testing.T) {
241244
err = os.Chdir(tempDir)
242245
assert.NoError(t, err)
243246

247+
// Set up config with the correct paths
248+
config.Config = *config.NewConfigType(tempDir, filepath.Join(tempDir, ".codacy"), filepath.Join(tempDir, ".cache", "codacy"))
249+
244250
// Create necessary directories
245251
err = config.Config.CreateLocalCodacyDir()
246252
assert.NoError(t, err)
247253
toolsConfigDir := config.Config.ToolsConfigDirectory()
248-
err = os.MkdirAll(toolsConfigDir, utils.DefaultFilePerms)
254+
err = os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms)
249255
assert.NoError(t, err)
250256

251257
// Reset initFlags to simulate local mode

0 commit comments

Comments
 (0)