From 086b0661d26907385538f15f6df4114ca00e7a93 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Wed, 13 Nov 2019 09:16:43 -0600 Subject: [PATCH] Remove unused and commented out code Change-Id: I92b325d7b78e26bbab21270ac9e52540a26c4ea1 --- cmd/config/config.go | 2 +- cmd/config/config_test.go | 91 ------------------- cmd/config/set_cluster_test.go | 7 -- .../config-cmd-with-defaults.golden | 2 +- .../config-cmd-with-help.golden | 2 +- pkg/config/config.go | 27 ------ 6 files changed, 3 insertions(+), 128 deletions(-) diff --git a/cmd/config/config.go b/cmd/config/config.go index 3626596e0..4ddc5f8c3 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -12,7 +12,7 @@ func NewConfigCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comma Use: "config", DisableFlagsInUseLine: true, Short: ("Modify airshipctl config files"), - Long: (`Modify airshipctl config files using subcommands + Long: (`Modify airshipctl config files using subcommands like "airshipctl config set-current-context my-context" `), } configRootCmd.AddCommand(NewCmdConfigSetCluster(rootSettings)) diff --git a/cmd/config/config_test.go b/cmd/config/config_test.go index c81967e28..c6531a1e3 100644 --- a/cmd/config/config_test.go +++ b/cmd/config/config_test.go @@ -17,34 +17,15 @@ limitations under the License. package config import ( - //"fmt" - //"os" - //"path/filepath" "testing" - //"github.com/stretchr/testify/assert" - //"github.com/stretchr/testify/require" - - "opendev.org/airship/airshipctl/pkg/config" - //"opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/testutil" ) -// Focus is only on testing config and its utcome with respect to the config file -// Specific outcome text will be tested by the appropriate _test - const ( testClusterName = "testCluster" ) -type configCommandTest struct { - description string - config *config.Config - args []string - flags []string - expectedConfig *config.Config -} - func TestConfig(t *testing.T) { cmdTests := []*testutil.CmdTest{ @@ -64,75 +45,3 @@ func TestConfig(t *testing.T) { testutil.RunTest(t, tt) } } - -/* This is failing for some reason, still investigating -Commenting everything to be able to uplad this patchset for review -Will fix afterwards - -func TestNewEmptyCluster(t *testing.T) { - - tname := testClusterName - tctype := config.Ephemeral - - airConfigFile := filepath.Join(config.AirshipConfigDir, config.AirshipConfig) - kConfigFile := filepath.Join(config.AirshipConfigDir, config.AirshipKubeConfig) - - // Remove everything in the config directory for this test - err := clean(config.AirshipConfigDir) - require.NoError(t, err) - - conf := config.InitConfigAt(t, airConfigFile, kConfigFile) - assert.Nil(t, err) - - expconf := config.NewConfig() - expconf.Clusters[tname] = config.NewClusterPurpose() - expconf.Clusters[tname].ClusterTypes[tctype] = config.NewCluster() - - clusterName := config.NewClusterComplexName() - clusterName.WithType(tname, tctype) - expconf.Clusters[tname].ClusterTypes[tctype].NameInKubeconf = clusterName.Name() - - test := configCommandTest{ - description: "Testing 'airshipctl config set-cluster' my-cluster", - config: conf, - args: []string{"set-cluster", - tname, - "--" + config.FlagClusterType + "=" + config.Ephemeral}, - flags: []string{}, - expectedConfig: expconf, - } - test.run(t) -} - -func (test configCommandTest) run(t *testing.T) { - - // Get the Environment - settings := &environment.AirshipCTLSettings{} - settings.SetConfig(test.config) - fmt.Printf("LoadedConfigPath:%s\nConfigIsLoaded %t\n", settings.Config().LoadedConfigPath(), settings.ConfigIsLoaded()) - fmt.Printf("Config:%s\nExpected:%s\n ", test.config, test.expectedConfig) - - cmd := NewConfigCommand(settings) - cmd.SetArgs(test.args) - err := cmd.Flags().Parse(test.flags) - require.NoErrorf(t, err, "unexpected error flags args to command: %v, flags: %v", err, test.flags) - - // Execute the Command - // Which should Persist the File - err = cmd.Execute() - require.NoErrorf(t, err, "unexpected error executing command: %v, args: %v, flags: %v", err, test.args, test.flags) - - // Load a New Config from the default Config File - afterSettings := &environment.AirshipCTLSettings{} - // Loads the Config File that was updated - afterSettings.InitConfig() - actualConfig := afterSettings.Config() - - assert.EqualValues(t, test.expectedConfig.String(), actualConfig.String()) - -} - -func clean(dst string) error { - return os.RemoveAll(dst) -} -*/ diff --git a/cmd/config/set_cluster_test.go b/cmd/config/set_cluster_test.go index 7452dd21b..12e7af1f7 100644 --- a/cmd/config/set_cluster_test.go +++ b/cmd/config/set_cluster_test.go @@ -119,9 +119,6 @@ func TestSetCluster(t *testing.T) { conf := config.InitConfig(t) - // err := conf.Purge() - // assert.Nilf(t, err, "Unable to purge test configuration %v", err) - tname := testCluster tctype := config.Ephemeral @@ -209,11 +206,7 @@ func (test setClusterTest) run(t *testing.T) { err = cmd.Execute() require.NoErrorf(t, err, "unexpected error executing command: %v, args: %v, flags: %v", err, test.args, test.flags) - // Load a New Config from the default Config File - //afterSettings := &environment.AirshipCTLSettings{} // Loads the Config File that was updated - //afterSettings.NewConfig() - // afterRunConf := afterSettings.GetConfig() afterRunConf := settings.Config() // Get ClusterType tctypeFlag := cmd.Flag(config.FlagClusterType) diff --git a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden index 3b3ead301..79a8d07b7 100644 --- a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden +++ b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-defaults.golden @@ -1,4 +1,4 @@ -Modify airshipctl config files using subcommands +Modify airshipctl config files using subcommands like "airshipctl config set-current-context my-context" Usage: diff --git a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden index 3b3ead301..79a8d07b7 100644 --- a/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden +++ b/cmd/config/testdata/TestConfigGoldenOutput/config-cmd-with-help.golden @@ -1,4 +1,4 @@ -Modify airshipctl config files using subcommands +Modify airshipctl config files using subcommands like "airshipctl config set-current-context my-context" Usage: diff --git a/pkg/config/config.go b/pkg/config/config.go index a08650582..95ce6fc21 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -462,33 +462,6 @@ func (c *Config) GetClusters() ([]*Cluster, error) { return clusters, nil } -// CurrentConfig Returns the appropriate information for the current context -// Current Context holds labels for the approriate config objects -// Cluster is the name of the cluster for this context -// ClusterType is the name of the clustertye for this context -// AuthInfo is the name of the authInfo for this context -// Manifest is the default manifest to be use with this context -// Namespace is the default namespace to use on unspecified requests -// Purpose for this method is simplifying ting the current context information -/* -func (c *Config) CurrentContext() (*Context, *Cluster, *AuthInfo, *Manifest, error) { - if err := c.EnsureComplete(); err != nil { - return nil, nil, nil, nil, err - } - currentContext := c.Contexts[c.CurrentContext] - if currentContext == nil { - // this should not happened - return nil, nil, nil, nil, - errors.New("CurrentContext was unable to find the configured current context.") - } - return currentContext, - c.Clusters[currentContext.Cluster].ClusterTypes[currentContext.ClusterType], - c.AuthInfos[currentContext.AuthInfo], - c.Manifests[currentContext.Manifest], - nil -} -*/ - // Purge removes the config file func (c *Config) Purge() error { //configFile := c.ConfigFile()