sigs.k8s.io/cluster-api-provider-aws@v1.5.5/pkg/cloud/services/iamauth/suite_test.go (about) 1 /* 2 Copyright 2022 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 iamauth 18 19 import ( 20 "fmt" 21 "path" 22 "testing" 23 24 utilruntime "k8s.io/apimachinery/pkg/util/runtime" 25 "k8s.io/client-go/kubernetes/scheme" 26 ctrl "sigs.k8s.io/controller-runtime" 27 28 infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1" 29 ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1" 30 expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/exp/api/v1beta1" 31 "sigs.k8s.io/cluster-api-provider-aws/test/helpers" 32 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 33 expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" 34 ) 35 36 var ( 37 testEnv *helpers.TestEnvironment 38 ctx = ctrl.SetupSignalHandler() 39 ) 40 41 func TestMain(m *testing.M) { 42 setup() 43 defer teardown() 44 m.Run() 45 } 46 47 func setup() { 48 utilruntime.Must(infrav1.AddToScheme(scheme.Scheme)) 49 utilruntime.Must(ekscontrolplanev1.AddToScheme(scheme.Scheme)) 50 utilruntime.Must(expinfrav1.AddToScheme(scheme.Scheme)) 51 utilruntime.Must(expclusterv1.AddToScheme(scheme.Scheme)) 52 utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme)) 53 54 testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{ 55 path.Join("config", "crd", "bases"), 56 }, 57 ).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml")) 58 var err error 59 testEnv, err = testEnvConfig.Build() 60 if err != nil { 61 panic(err) 62 } 63 if err := (&ekscontrolplanev1.AWSManagedControlPlane{}).SetupWebhookWithManager(testEnv); err != nil { 64 panic(fmt.Sprintf("Unable to setup AWSManagedControlPlane webhook: %v", err)) 65 } 66 if err := (&infrav1.AWSMachineTemplate{}).SetupWebhookWithManager(testEnv); err != nil { 67 panic(fmt.Sprintf("Unable to setup AWSMachineTemplate webhook: %v", err)) 68 } 69 if err := (&expinfrav1.AWSMachinePool{}).SetupWebhookWithManager(testEnv); err != nil { 70 panic(fmt.Sprintf("Unable to setup AWSMachineTemplate webhook: %v", err)) 71 } 72 if err := (&infrav1.AWSClusterControllerIdentity{}).SetupWebhookWithManager(testEnv); err != nil { 73 panic(fmt.Sprintf("Unable to setup AWSMachineTemplate webhook: %v", err)) 74 } 75 if err := (&expclusterv1.MachinePool{}).SetupWebhookWithManager(testEnv); err != nil { 76 panic(fmt.Sprintf("Unable to setup MachinePool webhook: %v", err)) 77 } 78 79 go func() { 80 fmt.Println("Starting the manager") 81 if err := testEnv.StartManager(ctx); err != nil { 82 panic(fmt.Sprintf("Failed to start the envtest manager: %v", err)) 83 } 84 }() 85 testEnv.WaitForWebhooks() 86 } 87 88 func teardown() { 89 if err := testEnv.Stop(); err != nil { 90 panic(fmt.Sprintf("Failed to stop envtest: %v", err)) 91 } 92 }