sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/controlleridentitycreator/awscontrolleridentity_controller_test.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package controlleridentitycreator 18 19 import ( 20 "context" 21 "testing" 22 "time" 23 24 "github.com/google/go-cmp/cmp" 25 . "github.com/onsi/gomega" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 "sigs.k8s.io/controller-runtime/pkg/client" 28 29 infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1" 30 ) 31 32 func TestAWSControllerIdentityController(t *testing.T) { 33 t.Run("should create AWSClusterControllerIdentity when identityRef is not specified", func(t *testing.T) { 34 g := NewWithT(t) 35 ctx := context.Background() 36 37 instance := &infrav1.AWSCluster{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}} 38 instance.Default() 39 40 // Create the AWSCluster object and expect the Reconcile and Deployment to be created 41 g.Expect(testEnv.Create(ctx, instance)).To(Succeed()) 42 43 t.Log("Ensuring AWSClusterControllerIdentity instance is created") 44 g.Eventually(func() bool { 45 cp := &infrav1.AWSClusterControllerIdentity{} 46 key := client.ObjectKey{ 47 Name: infrav1.AWSClusterControllerIdentityName, 48 } 49 err := testEnv.Get(ctx, key, cp) 50 if err != nil { 51 return false 52 } 53 if cmp.Equal(*cp.Spec.AllowedNamespaces, infrav1.AllowedNamespaces{}) { 54 return true 55 } 56 return false 57 }, 10*time.Second).Should(Equal(true)) 58 }) 59 }