sigs.k8s.io/cluster-api-provider-aws@v1.5.5/bootstrap/eks/api/v1alpha4/webhook_suite_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 v1alpha4 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 // +kubebuilder:scaffold:imports 29 eksbootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/bootstrap/eks/api/v1beta1" 30 "sigs.k8s.io/cluster-api-provider-aws/test/helpers" 31 ) 32 33 var ( 34 testEnv *helpers.TestEnvironment 35 ctx = ctrl.SetupSignalHandler() 36 ) 37 38 func TestMain(m *testing.M) { 39 setup() 40 defer teardown() 41 m.Run() 42 } 43 44 func setup() { 45 utilruntime.Must(AddToScheme(scheme.Scheme)) 46 utilruntime.Must(eksbootstrapv1.AddToScheme(scheme.Scheme)) 47 48 testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{ 49 path.Join("config", "crd", "bases"), 50 }, 51 ).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml")) 52 var err error 53 testEnv, err = testEnvConfig.Build() 54 if err != nil { 55 panic(err) 56 } 57 if err := (&eksbootstrapv1.EKSConfig{}).SetupWebhookWithManager(testEnv); err != nil { 58 panic(fmt.Sprintf("Unable to setup AWSCluster webhook: %v", err)) 59 } 60 if err := (&eksbootstrapv1.EKSConfigTemplate{}).SetupWebhookWithManager(testEnv); err != nil { 61 panic(fmt.Sprintf("Unable to setup AWSCluster webhook: %v", err)) 62 } 63 go func() { 64 fmt.Println("Starting the manager") 65 if err := testEnv.StartManager(ctx); err != nil { 66 panic(fmt.Sprintf("Failed to start the envtest manager: %v", err)) 67 } 68 }() 69 testEnv.WaitForWebhooks() 70 } 71 72 func teardown() { 73 if err := testEnv.Stop(); err != nil { 74 panic(fmt.Sprintf("Failed to stop envtest: %v", err)) 75 } 76 }