github.com/verrazzano/verrazzano@v1.7.0/cluster-operator/internal/k8s/kubeconfig_test.go (about) 1 // Copyright (c) 2021, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package k8s 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 // TestKubeConfig tests the building of a kubeconfig 13 // GIVEN a valid KubeconfigBuilder 14 // WHEN the Build function is called 15 // THEN the correct kubeconfig should be created 16 func TestKubeConfig(t *testing.T) { 17 const ( 18 b64Cert = "cert" 19 clusterName = "cluster" 20 contextName = "context" 21 serverURL = "url" 22 token = "token" 23 userName = "user" 24 ) 25 asserts := assert.New(t) 26 27 kb := KubeconfigBuilder{ 28 ClusterName: clusterName, 29 Server: serverURL, 30 CertAuth: b64Cert, 31 UserName: userName, 32 UserToken: string(token), 33 ContextName: contextName, 34 } 35 kc := kb.Build() 36 37 asserts.Equal(serverURL, kc.Clusters[0].Cluster.Server, "Incorrect server") 38 asserts.Equal(b64Cert, kc.Clusters[0].Cluster.CertAuth, "Incorrect certAuth") 39 asserts.Equal(userName, kc.Users[0].Name, "Incorrect username") 40 asserts.Equal(token, kc.Users[0].User.Token, "Incorrect token") 41 asserts.Equal(contextName, kc.Contexts[0].Name, "Incorrect context name") 42 asserts.Equal(userName, kc.Contexts[0].Context.User, "Incorrect context username") 43 asserts.Equal(clusterName, kc.Contexts[0].Context.Cluster, "Incorrect context clustername") 44 asserts.Equal(contextName, kc.CurrentContext, "Incorrect context") 45 }