github.com/verrazzano/verrazzano@v1.7.0/cluster-operator/internal/k8s/adminclusterconfig_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 "github.com/verrazzano/verrazzano/platform-operator/constants" 11 corev1 "k8s.io/api/core/v1" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 k8scheme "k8s.io/client-go/kubernetes/scheme" 14 "sigs.k8s.io/controller-runtime/pkg/client/fake" 15 ) 16 17 const testServerData = "https://testurl" 18 19 // TestGetApiServerURL tests the validation of a API server URL creation 20 // GIVEN a call validate GetAPIServerURL 21 // WHEN the verrazzano-admin-cluster configmap has the server data 22 // THEN the correct API URL shoule be returned 23 func TestGetApiServerURL(t *testing.T) { 24 client := fake.NewClientBuilder().WithScheme(k8scheme.Scheme).WithObjects( 25 &corev1.ConfigMap{ 26 ObjectMeta: metav1.ObjectMeta{ 27 Namespace: constants.VerrazzanoMultiClusterNamespace, 28 Name: constants.AdminClusterConfigMapName, 29 }, 30 Data: map[string]string{ 31 constants.ServerDataKey: testServerData, 32 }, 33 }, 34 ).Build() 35 36 url, err := GetAPIServerURL(client) 37 assert.NoError(t, err, "Error validating VerrazzanoMultiCluster resource") 38 assert.Equal(t, testServerData, url, "expected URL") 39 } 40 41 // TestGetApiServerURLErr tests the validation of a API server URL creation 42 // GIVEN a call validate GetAPIServerURL 43 // WHEN the verrazzano-admin-cluster configmap has the server data 44 // THEN the correct API URL shoule be returned 45 func TestGetApiServerURLErr(t *testing.T) { 46 client := fake.NewClientBuilder().WithScheme(k8scheme.Scheme).WithObjects( 47 &corev1.ConfigMap{ 48 ObjectMeta: metav1.ObjectMeta{ 49 Namespace: constants.VerrazzanoMultiClusterNamespace, 50 Name: constants.AdminClusterConfigMapName, 51 }, 52 Data: map[string]string{ 53 constants.ServerDataKey: testServerData, 54 }, 55 }, 56 ).Build() 57 58 url, err := GetAPIServerURL(client) 59 assert.NoError(t, err, "Error validating VerrazzanoMultiCluster resource") 60 assert.Equal(t, testServerData, url, "expected URL") 61 }