diff --git a/cmd/cmd_helpers_test.go b/cmd/cmd_helpers_test.go index 5e33166a..3f1699ef 100644 --- a/cmd/cmd_helpers_test.go +++ b/cmd/cmd_helpers_test.go @@ -6,7 +6,10 @@ import ( "github.com/spf13/cobra" ) -var pluginTestConfigFile = "./test.yaml" +var ( + globalTestConfigFile = "./test_global.yaml" + pluginTestConfigFile = "./test_plugins.yaml" +) // executeCommandC executes a cobra command and returns the command, output, and error. // Taken from https://github.com/spf13/cobra/blob/0c72800b8dba637092b57a955ecee75949e79a73/command_test.go#L48. diff --git a/cmd/config_init_test.go b/cmd/config_init_test.go index 1c737590..8c220cb2 100644 --- a/cmd/config_init_test.go +++ b/cmd/config_init_test.go @@ -9,28 +9,25 @@ import ( ) func Test_configInitCmd(t *testing.T) { - // Reset globalConfigFile to avoid conflicts with other tests. - globalConfigFile = "./test_config.yaml" - // Test configInitCmd. - output, err := executeCommandC(rootCmd, "config", "init", "-c", globalConfigFile) + output, err := executeCommandC(rootCmd, "config", "init", "-c", globalTestConfigFile) assert.NoError(t, err, "configInitCmd should not return an error") assert.Equal(t, - fmt.Sprintf("Config file '%s' was created successfully.", globalConfigFile), + fmt.Sprintf("Config file '%s' was created successfully.", globalTestConfigFile), output, "configInitCmd should print the correct output") // Check that the config file was created. - assert.FileExists(t, globalConfigFile, "configInitCmd should create a config file") + assert.FileExists(t, globalTestConfigFile, "configInitCmd should create a config file") // Test configInitCmd with the --force flag to overwrite the config file. output, err = executeCommandC(rootCmd, "config", "init", "--force") assert.NoError(t, err, "configInitCmd should not return an error") assert.Equal(t, - fmt.Sprintf("Config file '%s' was overwritten successfully.", globalConfigFile), + fmt.Sprintf("Config file '%s' was overwritten successfully.", globalTestConfigFile), output, "configInitCmd should print the correct output") // Clean up. - err = os.Remove(globalConfigFile) + err = os.Remove(globalTestConfigFile) assert.NoError(t, err) } diff --git a/cmd/config_lint_test.go b/cmd/config_lint_test.go index c046925e..82cf9a1a 100644 --- a/cmd/config_lint_test.go +++ b/cmd/config_lint_test.go @@ -9,21 +9,18 @@ import ( ) func Test_configLintCmd(t *testing.T) { - // Reset globalConfigFile to avoid conflicts with other tests. - globalConfigFile = "./test_config.yaml" - // Test configInitCmd. - output, err := executeCommandC(rootCmd, "config", "init", "-c", globalConfigFile) + output, err := executeCommandC(rootCmd, "config", "init", "-c", globalTestConfigFile) assert.NoError(t, err, "configInitCmd should not return an error") assert.Equal(t, - fmt.Sprintf("Config file '%s' was created successfully.", globalConfigFile), + fmt.Sprintf("Config file '%s' was created successfully.", globalTestConfigFile), output, "configInitCmd should print the correct output") // Check that the config file was created. - assert.FileExists(t, globalConfigFile, "configInitCmd should create a config file") + assert.FileExists(t, globalTestConfigFile, "configInitCmd should create a config file") // Test configLintCmd. - output, err = executeCommandC(rootCmd, "config", "lint", "-c", globalConfigFile) + output, err = executeCommandC(rootCmd, "config", "lint", "-c", globalTestConfigFile) assert.NoError(t, err, "configLintCmd should not return an error") assert.Equal(t, "global config is valid\n", @@ -31,6 +28,6 @@ func Test_configLintCmd(t *testing.T) { "configLintCmd should print the correct output") // Clean up. - err = os.Remove(globalConfigFile) + err = os.Remove(globalTestConfigFile) assert.NoError(t, err) } diff --git a/cmd/plugin_install_test.go b/cmd/plugin_install_test.go index a54efff0..0f931aa0 100644 --- a/cmd/plugin_install_test.go +++ b/cmd/plugin_install_test.go @@ -9,7 +9,7 @@ import ( ) func Test_pluginInstallCmd(t *testing.T) { - // Create a test config file. + // Create a test plugin config file. output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin init should not return an error") assert.Equal(t,