sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/instancestate/suite_test.go (about)

     1  /*
     2  Copyright 2020 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 instancestate
    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  	"sigs.k8s.io/controller-runtime/pkg/client"
    28  
    29  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    30  	expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/exp/api/v1beta1"
    31  	"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/instancestate/mock_sqsiface"
    32  	"sigs.k8s.io/cluster-api-provider-aws/test/helpers"
    33  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    34  	expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
    35  )
    36  
    37  // These tests use Ginkgo (BDD-style Go testing framework). Refer to
    38  // http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
    39  
    40  var (
    41  	k8sClient               client.Client
    42  	instanceStateReconciler *AwsInstanceStateReconciler
    43  	sqsSvs                  *mock_sqsiface.MockSQSAPI
    44  	testEnv                 *helpers.TestEnvironment
    45  	ctx                     = ctrl.SetupSignalHandler()
    46  )
    47  
    48  func TestMain(m *testing.M) {
    49  	setup()
    50  	defer teardown()
    51  	m.Run()
    52  }
    53  
    54  func setup() {
    55  	utilruntime.Must(infrav1.AddToScheme(scheme.Scheme))
    56  	utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme))
    57  	utilruntime.Must(expinfrav1.AddToScheme(scheme.Scheme))
    58  	utilruntime.Must(expclusterv1.AddToScheme(scheme.Scheme))
    59  	testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
    60  		path.Join("config", "crd", "bases"),
    61  	},
    62  	).WithWebhookConfiguration("unmanaged", path.Join("config", "webhook", "manifests.yaml"))
    63  	var err error
    64  	testEnv, err = testEnvConfig.Build()
    65  	if err != nil {
    66  		panic(err)
    67  	}
    68  	if err := (&infrav1.AWSCluster{}).SetupWebhookWithManager(testEnv); err != nil {
    69  		panic(fmt.Sprintf("Unable to setup AWSCluster webhook: %v", err))
    70  	}
    71  	if err := (&infrav1.AWSMachine{}).SetupWebhookWithManager(testEnv); err != nil {
    72  		panic(fmt.Sprintf("Unable to setup AWSMachine webhook: %v", err))
    73  	}
    74  	if err := (&infrav1.AWSMachineTemplate{}).SetupWebhookWithManager(testEnv); err != nil {
    75  		panic(fmt.Sprintf("Unable to setup AWSMachineTemplate webhook: %v", err))
    76  	}
    77  	if err := (&expinfrav1.AWSMachinePool{}).SetupWebhookWithManager(testEnv); err != nil {
    78  		panic(fmt.Sprintf("Unable to setup AWSMachinePool webhook: %v", err))
    79  	}
    80  	if err := (&expinfrav1.AWSManagedMachinePool{}).SetupWebhookWithManager(testEnv); err != nil {
    81  		panic(fmt.Sprintf("Unable to setup AWSManagedMachinePool webhook: %v", err))
    82  	}
    83  }
    84  
    85  func teardown() {
    86  	if err := testEnv.Stop(); err != nil {
    87  		panic(fmt.Sprintf("Failed to stop envtest: %v", err))
    88  	}
    89  }