@@ -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