Merge "[#47] Switch config module to black box testing"

This commit is contained in:
Zuul 2020-02-17 17:15:17 +00:00 committed by Gerrit Code Review
commit f4e75e2152
2 changed files with 159 additions and 196 deletions

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package config
package config_test
import (
"fmt"
@ -26,8 +26,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kubeconfig "k8s.io/client-go/tools/clientcmd/api"
"opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/testutil"
)
@ -42,51 +41,51 @@ func TestString(t *testing.T) {
}{
{
name: "config",
stringer: DummyConfig(),
stringer: config.DummyConfig(),
},
{
name: "context",
stringer: DummyContext(),
stringer: config.DummyContext(),
},
{
name: "cluster",
stringer: DummyCluster(),
stringer: config.DummyCluster(),
},
{
name: "authinfo",
stringer: DummyAuthInfo(),
stringer: config.DummyAuthInfo(),
},
{
name: "manifest",
stringer: DummyManifest(),
stringer: config.DummyManifest(),
},
{
name: "modules",
stringer: DummyModules(),
stringer: config.DummyModules(),
},
{
name: "repository",
stringer: DummyRepository(),
stringer: config.DummyRepository(),
},
{
name: "repo-auth",
stringer: DummyRepoAuth(),
stringer: config.DummyRepoAuth(),
},
{
name: "repo-checkout",
stringer: DummyRepoCheckout(),
stringer: config.DummyRepoCheckout(),
},
{
name: "bootstrap",
stringer: DummyBootstrap(),
stringer: config.DummyBootstrap(),
},
{
name: "bootstrap",
stringer: DummyBootstrap(),
stringer: config.DummyBootstrap(),
},
{
name: "builder",
stringer: &Builder{
stringer: &config.Builder{
UserDataFileName: "user-data",
NetworkConfigFileName: "netconfig",
OutputMetadataFileName: "output-metadata.yaml",
@ -94,7 +93,7 @@ func TestString(t *testing.T) {
},
{
name: "container",
stringer: &Container{
stringer: &config.Container{
Volume: "/dummy:dummy",
Image: "dummy_image:dummy_tag",
ContainerRuntime: "docker",
@ -119,14 +118,14 @@ func TestPrettyString(t *testing.T) {
data, err := fSys.ReadFile("/prettycluster-string.yaml")
require.NoError(t, err)
cluster := DummyCluster()
cluster := config.DummyCluster()
assert.EqualValues(t, cluster.PrettyString(), string(data))
}
func TestEqual(t *testing.T) {
t.Run("config-equal", func(t *testing.T) {
testConfig1 := NewConfig()
testConfig2 := NewConfig()
testConfig1 := config.NewConfig()
testConfig2 := config.NewConfig()
testConfig2.Kind = "Different"
assert.True(t, testConfig1.Equal(testConfig1))
assert.False(t, testConfig1.Equal(testConfig2))
@ -134,16 +133,16 @@ func TestEqual(t *testing.T) {
})
t.Run("cluster-equal", func(t *testing.T) {
testCluster1 := &Cluster{NameInKubeconf: "same"}
testCluster2 := &Cluster{NameInKubeconf: "different"}
testCluster1 := &config.Cluster{NameInKubeconf: "same"}
testCluster2 := &config.Cluster{NameInKubeconf: "different"}
assert.True(t, testCluster1.Equal(testCluster1))
assert.False(t, testCluster1.Equal(testCluster2))
assert.False(t, testCluster1.Equal(nil))
})
t.Run("context-equal", func(t *testing.T) {
testContext1 := &Context{NameInKubeconf: "same"}
testContext2 := &Context{NameInKubeconf: "different"}
testContext1 := &config.Context{NameInKubeconf: "same"}
testContext2 := &config.Context{NameInKubeconf: "different"}
assert.True(t, testContext1.Equal(testContext1))
assert.False(t, testContext1.Equal(testContext2))
assert.False(t, testContext1.Equal(nil))
@ -151,37 +150,37 @@ func TestEqual(t *testing.T) {
// TODO(howell): this needs to be fleshed out when the AuthInfo type is finished
t.Run("authinfo-equal", func(t *testing.T) {
testAuthInfo1 := &AuthInfo{}
testAuthInfo1 := &config.AuthInfo{}
assert.True(t, testAuthInfo1.Equal(testAuthInfo1))
assert.False(t, testAuthInfo1.Equal(nil))
})
t.Run("manifest-equal", func(t *testing.T) {
testManifest1 := &Manifest{TargetPath: "same"}
testManifest2 := &Manifest{TargetPath: "different"}
testManifest1 := &config.Manifest{TargetPath: "same"}
testManifest2 := &config.Manifest{TargetPath: "different"}
assert.True(t, testManifest1.Equal(testManifest1))
assert.False(t, testManifest1.Equal(testManifest2))
assert.False(t, testManifest1.Equal(nil))
})
t.Run("repository-equal", func(t *testing.T) {
testRepository1 := &Repository{URLString: "same"}
testRepository2 := &Repository{URLString: "different"}
testRepository1 := &config.Repository{URLString: "same"}
testRepository2 := &config.Repository{URLString: "different"}
assert.True(t, testRepository1.Equal(testRepository1))
assert.False(t, testRepository1.Equal(testRepository2))
assert.False(t, testRepository1.Equal(nil))
})
t.Run("auth-equal", func(t *testing.T) {
testSpec1 := &RepoAuth{}
testSpec2 := &RepoAuth{}
testSpec1 := &config.RepoAuth{}
testSpec2 := &config.RepoAuth{}
testSpec2.Type = "ssh-key"
assert.True(t, testSpec1.Equal(testSpec1))
assert.False(t, testSpec1.Equal(testSpec2))
assert.False(t, testSpec1.Equal(nil))
})
t.Run("checkout-equal", func(t *testing.T) {
testSpec1 := &RepoCheckout{}
testSpec2 := &RepoCheckout{}
testSpec1 := &config.RepoCheckout{}
testSpec2 := &config.RepoCheckout{}
testSpec2.Branch = "Master"
assert.True(t, testSpec1.Equal(testSpec1))
assert.False(t, testSpec1.Equal(testSpec2))
@ -189,10 +188,10 @@ func TestEqual(t *testing.T) {
})
t.Run("modules-equal", func(t *testing.T) {
testModules1 := NewModules()
testModules2 := NewModules()
testModules2.BootstrapInfo["different"] = &Bootstrap{
Container: &Container{Volume: "different"},
testModules1 := config.NewModules()
testModules2 := config.NewModules()
testModules2.BootstrapInfo["different"] = &config.Bootstrap{
Container: &config.Container{Volume: "different"},
}
assert.True(t, testModules1.Equal(testModules1))
assert.False(t, testModules1.Equal(testModules2))
@ -200,13 +199,13 @@ func TestEqual(t *testing.T) {
})
t.Run("bootstrap-equal", func(t *testing.T) {
testBootstrap1 := &Bootstrap{
Container: &Container{
testBootstrap1 := &config.Bootstrap{
Container: &config.Container{
Image: "same",
},
}
testBootstrap2 := &Bootstrap{
Container: &Container{
testBootstrap2 := &config.Bootstrap{
Container: &config.Container{
Image: "different",
},
}
@ -216,16 +215,16 @@ func TestEqual(t *testing.T) {
})
t.Run("container-equal", func(t *testing.T) {
testContainer1 := &Container{Image: "same"}
testContainer2 := &Container{Image: "different"}
testContainer1 := &config.Container{Image: "same"}
testContainer2 := &config.Container{Image: "different"}
assert.True(t, testContainer1.Equal(testContainer1))
assert.False(t, testContainer1.Equal(testContainer2))
assert.False(t, testContainer1.Equal(nil))
})
t.Run("builder-equal", func(t *testing.T) {
testBuilder1 := &Builder{UserDataFileName: "same"}
testBuilder2 := &Builder{UserDataFileName: "different"}
testBuilder1 := &config.Builder{UserDataFileName: "same"}
testBuilder2 := &config.Builder{UserDataFileName: "different"}
assert.True(t, testBuilder1.Equal(testBuilder1))
assert.False(t, testBuilder1.Equal(testBuilder2))
assert.False(t, testBuilder1.Equal(nil))
@ -233,10 +232,10 @@ func TestEqual(t *testing.T) {
}
func TestLoadConfig(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
require.NotEmpty(t, conf.String())
assert.Len(t, conf.Clusters, 4)
assert.Len(t, conf.Clusters, 5)
require.Contains(t, conf.Clusters, "def")
assert.Len(t, conf.Clusters["def"].ClusterTypes, 2)
assert.Len(t, conf.Contexts, 3)
@ -244,14 +243,22 @@ func TestLoadConfig(t *testing.T) {
}
func TestPersistConfig(t *testing.T) {
config := InitConfig(t)
cfg := config.InitConfig(t)
err := config.PersistConfig()
err := cfg.PersistConfig()
require.NoError(t, err)
// Check that the files were created
assert.FileExists(t, config.LoadedConfigPath())
assert.FileExists(t, config.KubeConfigPath())
assert.FileExists(t, cfg.LoadedConfigPath())
assert.FileExists(t, cfg.KubeConfigPath())
// Check that the invalid name was changed to a valid one
assert.Contains(t, cfg.KubeConfig().Clusters, "invalidName_target")
// Check that the missing cluster was added to the airshipconfig
assert.Contains(t, cfg.ClusterNames(), "onlyinkubeconf")
// Check that the "stragglers" were removed from the airshipconfig
assert.NotContains(t, cfg.ClusterNames(), "straggler")
}
func TestEnsureComplete(t *testing.T) {
@ -261,93 +268,93 @@ func TestEnsureComplete(t *testing.T) {
// be otherwise valid
tests := []struct {
name string
config Config
config config.Config
expectedErr error
}{
{
name: "no clusters defined",
config: Config{
Clusters: map[string]*ClusterPurpose{},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{"testManifest": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{"testManifest": {}},
CurrentContext: "testContext",
},
expectedErr: ErrMissingConfig{What: "At least one cluster needs to be defined"},
expectedErr: config.ErrMissingConfig{What: "At least one cluster needs to be defined"},
},
{
name: "no users defined",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{},
Contexts: map[string]*Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{"testManifest": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{},
Contexts: map[string]*config.Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{"testManifest": {}},
CurrentContext: "testContext",
},
expectedErr: ErrMissingConfig{What: "At least one Authentication Information (User) needs to be defined"},
expectedErr: config.ErrMissingConfig{What: "At least one Authentication Information (User) needs to be defined"},
},
{
name: "no contexts defined",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{},
Manifests: map[string]*Manifest{"testManifest": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{},
Manifests: map[string]*config.Manifest{"testManifest": {}},
CurrentContext: "testContext",
},
expectedErr: ErrMissingConfig{What: "At least one Context needs to be defined"},
expectedErr: config.ErrMissingConfig{What: "At least one Context needs to be defined"},
},
{
name: "no manifests defined",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{},
CurrentContext: "testContext",
},
expectedErr: ErrMissingConfig{What: "At least one Manifest needs to be defined"},
expectedErr: config.ErrMissingConfig{What: "At least one Manifest needs to be defined"},
},
{
name: "current context not defined",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{"testManifest": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{"testManifest": {}},
CurrentContext: "",
},
expectedErr: ErrMissingConfig{What: "Current Context is not defined"},
expectedErr: config.ErrMissingConfig{What: "Current Context is not defined"},
},
{
name: "no context for current context",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{"DIFFERENT_CONTEXT": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{"testManifest": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{"DIFFERENT_CONTEXT": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{"testManifest": {}},
CurrentContext: "testContext",
},
expectedErr: ErrMissingConfig{What: "Current Context (testContext) does not identify a defined Context"},
expectedErr: config.ErrMissingConfig{What: "Current Context (testContext) does not identify a defined Context"},
},
{
name: "no manifest for current context",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{"DIFFERENT_MANIFEST": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{"DIFFERENT_MANIFEST": {}},
CurrentContext: "testContext",
},
expectedErr: ErrMissingConfig{What: "Current Context (testContext) does not identify a defined Manifest"},
expectedErr: config.ErrMissingConfig{What: "Current Context (testContext) does not identify a defined Manifest"},
},
{
name: "complete config",
config: Config{
Clusters: map[string]*ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*Manifest{"testManifest": {}},
config: config.Config{
Clusters: map[string]*config.ClusterPurpose{"testCluster": {}},
AuthInfos: map[string]*config.AuthInfo{"testAuthInfo": {}},
Contexts: map[string]*config.Context{"testContext": {Manifest: "testManifest"}},
Manifests: map[string]*config.Manifest{"testManifest": {}},
CurrentContext: "testContext",
},
expectedErr: nil,
@ -364,65 +371,65 @@ func TestEnsureComplete(t *testing.T) {
}
func TestPurge(t *testing.T) {
config := InitConfig(t)
cfg := config.InitConfig(t)
// Point the config objects at a temporary directory
tempDir, err := ioutil.TempDir("", "airship-test-purge")
require.NoError(t, err)
airConfigFile := filepath.Join(tempDir, AirshipConfig)
config.SetLoadedConfigPath(airConfigFile)
airConfigFile := filepath.Join(tempDir, config.AirshipConfig)
cfg.SetLoadedConfigPath(airConfigFile)
kConfigFile := filepath.Join(tempDir, AirshipKubeConfig)
config.kubeConfigPath = kConfigFile
kConfigFile := filepath.Join(tempDir, config.AirshipKubeConfig)
cfg.SetKubeConfigPath(kConfigFile)
// Store it
err = config.PersistConfig()
assert.NoErrorf(t, err, "Unable to persist configuration expected at %v", config.LoadedConfigPath())
err = cfg.PersistConfig()
assert.NoErrorf(t, err, "Unable to persist configuration expected at %v", cfg.LoadedConfigPath())
// Verify that the file is there
_, err = os.Stat(config.LoadedConfigPath())
_, err = os.Stat(cfg.LoadedConfigPath())
assert.Falsef(t, os.IsNotExist(err), "Test config was not persisted at %v, cannot validate Purge",
config.LoadedConfigPath())
cfg.LoadedConfigPath())
// Delete it
err = config.Purge()
assert.NoErrorf(t, err, "Unable to Purge file at %v", config.LoadedConfigPath())
err = cfg.Purge()
assert.NoErrorf(t, err, "Unable to Purge file at %v", cfg.LoadedConfigPath())
// Verify its gone
_, err = os.Stat(config.LoadedConfigPath())
assert.Falsef(t, os.IsExist(err), "Purge failed to remove file at %v", config.LoadedConfigPath())
_, err = os.Stat(cfg.LoadedConfigPath())
assert.Falsef(t, os.IsExist(err), "Purge failed to remove file at %v", cfg.LoadedConfigPath())
}
func TestKClusterString(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
kClusters := conf.KubeConfig().Clusters
for kClust := range kClusters {
assert.NotEmpty(t, KClusterString(kClusters[kClust]))
assert.NotEmpty(t, config.KClusterString(kClusters[kClust]))
}
assert.EqualValues(t, KClusterString(nil), "null\n")
assert.EqualValues(t, config.KClusterString(nil), "null\n")
}
func TestKContextString(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
kContexts := conf.KubeConfig().Contexts
for kCtx := range kContexts {
assert.NotEmpty(t, KContextString(kContexts[kCtx]))
assert.NotEmpty(t, config.KContextString(kContexts[kCtx]))
}
assert.EqualValues(t, KClusterString(nil), "null\n")
assert.EqualValues(t, config.KClusterString(nil), "null\n")
}
func TestKAuthInfoString(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
kAuthInfos := conf.KubeConfig().AuthInfos
for kAi := range kAuthInfos {
assert.NotEmpty(t, KAuthInfoString(kAuthInfos[kAi]))
assert.NotEmpty(t, config.KAuthInfoString(kAuthInfos[kAi]))
}
assert.EqualValues(t, KAuthInfoString(nil), "null\n")
assert.EqualValues(t, config.KAuthInfoString(nil), "null\n")
}
func TestComplexName(t *testing.T) {
cName := "aCluster"
ctName := Ephemeral
clusterName := NewClusterComplexName()
ctName := config.Ephemeral
clusterName := config.NewClusterComplexName()
clusterName.WithType(cName, ctName)
assert.EqualValues(t, cName+"_"+ctName, clusterName.Name())
@ -438,12 +445,12 @@ func TestComplexName(t *testing.T) {
}
func TestValidClusterTypeFail(t *testing.T) {
err := ValidClusterType("Fake")
err := config.ValidClusterType("Fake")
assert.Error(t, err)
}
func TestGetCluster(t *testing.T) {
conf := InitConfig(t)
cluster, err := conf.GetCluster("def", Ephemeral)
conf := config.InitConfig(t)
cluster, err := conf.GetCluster("def", config.Ephemeral)
require.NoError(t, err)
// Test Positives
@ -451,7 +458,7 @@ func TestGetCluster(t *testing.T) {
assert.EqualValues(t, cluster.KubeCluster().Server, "http://5.6.7.8")
// Test Wrong Cluster
_, err = conf.GetCluster("unknown", Ephemeral)
_, err = conf.GetCluster("unknown", config.Ephemeral)
assert.Error(t, err)
// Test Wrong Cluster Type
@ -460,8 +467,8 @@ func TestGetCluster(t *testing.T) {
}
func TestAddCluster(t *testing.T) {
co := DummyClusterOptions()
conf := InitConfig(t)
co := config.DummyClusterOptions()
conf := config.InitConfig(t)
cluster, err := conf.AddCluster(co)
require.NoError(t, err)
@ -469,8 +476,8 @@ func TestAddCluster(t *testing.T) {
}
func TestModifyCluster(t *testing.T) {
co := DummyClusterOptions()
conf := InitConfig(t)
co := config.DummyClusterOptions()
conf := config.InitConfig(t)
cluster, err := conf.AddCluster(co)
require.NoError(t, err)
@ -489,73 +496,21 @@ func TestModifyCluster(t *testing.T) {
}
func TestGetClusters(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
clusters, err := conf.GetClusters()
require.NoError(t, err)
assert.Len(t, clusters, 4)
}
func TestReconcileClusters(t *testing.T) {
testCluster := &kubeconfig.Cluster{
Server: "testServer",
InsecureSkipTLSVerify: true,
}
testKubeConfig := &kubeconfig.Config{
Clusters: map[string]*kubeconfig.Cluster{
"invalidName": nil,
"missingFromAirshipConfig_ephemeral": testCluster,
},
}
testConfig := &Config{
Clusters: map[string]*ClusterPurpose{
"straggler": {
map[string]*Cluster{
"ephemeral": {
NameInKubeconf: "notThere!",
kCluster: nil,
},
},
},
},
kubeConfig: testKubeConfig,
}
updatedClusterNames, persistIt := testConfig.reconcileClusters()
// Check that there are clusters that need to be updated in contexts
expectedUpdatedClusterNames := map[string]string{"invalidName": "invalidName_target"}
assert.Equal(t, expectedUpdatedClusterNames, updatedClusterNames)
// Check that we need to update the config file
assert.True(t, persistIt)
// Check that the invalid name was changed to a valid one
assert.NotContains(t, testKubeConfig.Clusters, "invalidName")
assert.Contains(t, testKubeConfig.Clusters, "invalidName_target")
// Check that the missing cluster was added to the airshipconfig
missingCluster := testConfig.Clusters["missingFromAirshipConfig"]
require.NotNil(t, missingCluster)
require.NotNil(t, missingCluster.ClusterTypes)
require.NotNil(t, missingCluster.ClusterTypes[Ephemeral])
assert.Equal(t, "missingFromAirshipConfig_ephemeral",
missingCluster.ClusterTypes[Ephemeral].NameInKubeconf)
assert.Equal(t, testCluster, missingCluster.ClusterTypes[Ephemeral].kCluster)
// Check that the "stragglers" were removed from the airshipconfig
assert.NotContains(t, testConfig.Clusters, "straggler")
assert.Len(t, clusters, 5)
}
func TestGetContexts(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
contexts, err := conf.GetContexts()
require.NoError(t, err)
assert.Len(t, contexts, 3)
}
func TestGetContext(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
context, err := conf.GetContext("def_ephemeral")
require.NoError(t, err)
@ -569,15 +524,15 @@ func TestGetContext(t *testing.T) {
}
func TestAddContext(t *testing.T) {
co := DummyContextOptions()
conf := InitConfig(t)
co := config.DummyContextOptions()
conf := config.InitConfig(t)
context := conf.AddContext(co)
assert.EqualValues(t, conf.Contexts[co.Name], context)
}
func TestModifyContext(t *testing.T) {
co := DummyContextOptions()
conf := InitConfig(t)
co := config.DummyContextOptions()
conf := config.InitConfig(t)
context := conf.AddContext(co)
co.Namespace += stringDelta
@ -595,14 +550,14 @@ func TestModifyContext(t *testing.T) {
// AuthInfo Related
func TestGetAuthInfos(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
authinfos, err := conf.GetAuthInfos()
require.NoError(t, err)
assert.Len(t, authinfos, 3)
}
func TestGetAuthInfo(t *testing.T) {
conf := InitConfig(t)
conf := config.InitConfig(t)
authinfo, err := conf.GetAuthInfo("def-user")
require.NoError(t, err)
@ -615,15 +570,15 @@ func TestGetAuthInfo(t *testing.T) {
}
func TestAddAuthInfo(t *testing.T) {
co := DummyAuthInfoOptions()
conf := InitConfig(t)
co := config.DummyAuthInfoOptions()
conf := config.InitConfig(t)
authinfo := conf.AddAuthInfo(co)
assert.EqualValues(t, conf.AuthInfos[co.Name], authinfo)
}
func TestModifyAuthInfo(t *testing.T) {
co := DummyAuthInfoOptions()
conf := InitConfig(t)
co := config.DummyAuthInfoOptions()
conf := config.InitConfig(t)
authinfo := conf.AddAuthInfo(co)
co.Username += stringDelta

View File

@ -221,6 +221,10 @@ func DummyBootstrap() *Bootstrap {
const (
testConfigYAML = `apiVersion: airshipit.org/v1alpha1
clusters:
straggler:
cluster-type:
ephemeral:
cluster-kubeconf: notThere
def:
cluster-type:
ephemeral:
@ -277,6 +281,10 @@ clusters:
certificate-authority: cert_file
server: ""
name: wrongonlyinkubeconf_target
- cluster:
insecure-skip-tls-verify: true
server: http://9.10.11.12
name: invalidName
contexts:
- context:
cluster: def_ephemeral