From 404a09356bc5df80278c648d6adc727bbf62d913 Mon Sep 17 00:00:00 2001 From: Sirajudeen Date: Mon, 20 Jul 2020 17:39:01 -0500 Subject: [PATCH] Added unit test for missing config functions * Added more unit tests to increase test coverage Change-Id: I30592465cc08528145a8f309fe9b8c403824ccf1 --- cmd/config/get_management_config_test.go | 8 ++++++++ cmd/config/set_management_configuration_test.go | 5 +++++ .../config-cmd-set-management-config-no-change.golden | 1 + .../get-empty-management-config.golden | 1 + pkg/environment/settings_test.go | 6 +++--- 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 cmd/config/testdata/TestConfigSetManagementConfigurationInsecureGoldenOutput/config-cmd-set-management-config-no-change.golden create mode 100644 cmd/config/testdata/TestGetManagementConfigCmdGoldenOutput/get-empty-management-config.golden diff --git a/cmd/config/get_management_config_test.go b/cmd/config/get_management_config_test.go index d0aa09ff9..3f1f6f85f 100644 --- a/cmd/config/get_management_config_test.go +++ b/cmd/config/get_management_config_test.go @@ -37,6 +37,9 @@ func TestGetManagementConfigCmd(t *testing.T) { }, }, } + emptySettings := &environment.AirshipCTLSettings{ + Config: &config.Config{}, + } cmdTests := []*testutil.CmdTest{ { @@ -60,6 +63,11 @@ func TestGetManagementConfigCmd(t *testing.T) { CmdLine: config.AirshipDefaultContext, Cmd: cmd.NewGetManagementConfigCommand(settings), }, + { + Name: "get-empty-management-config", + CmdLine: "", + Cmd: cmd.NewGetManagementConfigCommand(emptySettings), + }, } for _, tt := range cmdTests { diff --git a/cmd/config/set_management_configuration_test.go b/cmd/config/set_management_configuration_test.go index d25f78751..369ecfe24 100644 --- a/cmd/config/set_management_configuration_test.go +++ b/cmd/config/set_management_configuration_test.go @@ -84,6 +84,11 @@ func TestConfigSetManagementConfigurationInsecure(t *testing.T) { CmdLine: fmt.Sprintf("%s --insecure=true", config.AirshipDefaultContext), Cmd: cmd.NewSetManagementConfigCommand(settings), }) + testutil.RunTest(t, &testutil.CmdTest{ + Name: "config-cmd-set-management-config-no-change", + CmdLine: fmt.Sprintf("%s --insecure=true", config.AirshipDefaultContext), + Cmd: cmd.NewSetManagementConfigCommand(settings), + }) assert.True(t, settings.Config.ManagementConfiguration[config.AirshipDefaultContext].Insecure) } diff --git a/cmd/config/testdata/TestConfigSetManagementConfigurationInsecureGoldenOutput/config-cmd-set-management-config-no-change.golden b/cmd/config/testdata/TestConfigSetManagementConfigurationInsecureGoldenOutput/config-cmd-set-management-config-no-change.golden new file mode 100644 index 000000000..33d7fd879 --- /dev/null +++ b/cmd/config/testdata/TestConfigSetManagementConfigurationInsecureGoldenOutput/config-cmd-set-management-config-no-change.golden @@ -0,0 +1 @@ +Management configuration 'default' not modified. No new settings. diff --git a/cmd/config/testdata/TestGetManagementConfigCmdGoldenOutput/get-empty-management-config.golden b/cmd/config/testdata/TestGetManagementConfigCmdGoldenOutput/get-empty-management-config.golden new file mode 100644 index 000000000..f9e7753d2 --- /dev/null +++ b/cmd/config/testdata/TestGetManagementConfigCmdGoldenOutput/get-empty-management-config.golden @@ -0,0 +1 @@ +No management configurations defined. diff --git a/pkg/environment/settings_test.go b/pkg/environment/settings_test.go index 3d6adf342..2d7975a10 100644 --- a/pkg/environment/settings_test.go +++ b/pkg/environment/settings_test.go @@ -75,9 +75,9 @@ func TestInitConfig(t *testing.T) { defer os.Unsetenv(config.AirshipKubeConfigEnv) defer os.Unsetenv(config.AirshipPluginPathEnv) - testSettings.InitAirshipConfigPath() - testSettings.InitKubeConfigPath() - environment.InitPluginPath() + testSettings.Create = true + testSettings.InitConfig() + assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath) assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath) assert.Equal(t, expectedPluginPath, environment.PluginPath())