Merge "Remove unused and commented out code"

This commit is contained in:
Zuul 2019-11-15 16:46:08 +00:00 committed by Gerrit Code Review
commit 80621d71e5
6 changed files with 3 additions and 128 deletions

View File

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

View File

@ -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 <subcommand>_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)
}
*/

View File

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

View File

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

View File

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

View File

@ -482,33 +482,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()