Skip to content

Commit ab92926

Browse files
fixed test
1 parent 84001ec commit ab92926

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cmd/analyze_integration_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func TestCheckIfConfigExistsAndIsNeededBehavior(t *testing.T) {
8888
// Mock config to use our temporary directory
8989
config.Config = *config.NewConfigType(tmpDir, tmpDir, tmpDir)
9090

91+
// Create tools-configs directory since the function will try to create config files
92+
toolsConfigDir := config.Config.ToolsConfigDirectory()
93+
err = os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms)
94+
require.NoError(t, err)
95+
9196
// Execute the function - this tests it doesn't panic or return unexpected errors
9297
err = checkIfConfigExistsAndIsNeeded(tt.toolName, tt.cliLocalMode)
9398

cmd/analyze_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func TestCheckIfConfigExistsAndIsNeeded(t *testing.T) {
324324
apiToken: "",
325325
configFileExists: false,
326326
expectError: false,
327-
description: "Local mode should show message about adding config file",
327+
description: "Local mode should create config file if tools-configs directory exists",
328328
},
329329
}
330330

@@ -346,11 +346,11 @@ func TestCheckIfConfigExistsAndIsNeeded(t *testing.T) {
346346
if tt.configFileExists && constants.ToolConfigFileNames[tt.toolName] != "" {
347347
// Use config.Config.ToolsConfigDirectory() to get the exact same path the function will use
348348
toolsConfigDir := config.Config.ToolsConfigDirectory()
349-
err := os.MkdirAll(toolsConfigDir, 0755)
349+
err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms)
350350
require.NoError(t, err)
351351

352352
configPath := filepath.Join(toolsConfigDir, constants.ToolConfigFileNames[tt.toolName])
353-
err = os.WriteFile(configPath, []byte("test config"), 0644)
353+
err = os.WriteFile(configPath, []byte("test config"), constants.DefaultFilePerms)
354354
require.NoError(t, err)
355355

356356
// Ensure the file was created and can be found
@@ -363,6 +363,13 @@ func TestCheckIfConfigExistsAndIsNeeded(t *testing.T) {
363363
ApiToken: tt.apiToken,
364364
}
365365

366+
// Ensure tools-configs directory exists if the function might try to create config files
367+
if !tt.configFileExists && constants.ToolConfigFileNames[tt.toolName] != "" {
368+
toolsConfigDir := config.Config.ToolsConfigDirectory()
369+
err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms)
370+
require.NoError(t, err)
371+
}
372+
366373
// Execute the function
367374
err = checkIfConfigExistsAndIsNeeded(tt.toolName, tt.cliLocalMode)
368375

0 commit comments

Comments
 (0)