sigs.k8s.io/cluster-api-provider-azure@v1.14.3/controllers/suite_test.go (about)

     1  /*
     2  Copyright 2019 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 controllers
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  	corev1 "k8s.io/api/core/v1"
    26  	"sigs.k8s.io/cluster-api-provider-azure/internal/test/env"
    27  	"sigs.k8s.io/cluster-api-provider-azure/util/reconciler"
    28  	"sigs.k8s.io/controller-runtime/pkg/controller"
    29  )
    30  
    31  // These tests use Ginkgo (BDD-style Go testing framework). Refer to
    32  // http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
    33  
    34  var (
    35  	testEnv       *env.TestEnvironment
    36  	testEnvCancel func()
    37  )
    38  
    39  func TestAPIs(t *testing.T) {
    40  	RegisterFailHandler(Fail)
    41  	RunSpecs(t, "Controller Suite")
    42  }
    43  
    44  var _ = BeforeSuite(func() {
    45  	By("bootstrapping test environment")
    46  	testEnv = env.NewTestEnvironment()
    47  	Expect(NewAzureClusterReconciler(testEnv, testEnv.GetEventRecorderFor("azurecluster-reconciler"), reconciler.Timeouts{}, "").
    48  		SetupWithManager(context.Background(), testEnv.Manager, Options{Options: controller.Options{MaxConcurrentReconciles: 1}})).To(Succeed())
    49  
    50  	Expect(NewAzureMachineReconciler(testEnv, testEnv.GetEventRecorderFor("azuremachine-reconciler"), reconciler.Timeouts{}, "").
    51  		SetupWithManager(context.Background(), testEnv.Manager, Options{Options: controller.Options{MaxConcurrentReconciles: 1}})).To(Succeed())
    52  
    53  	Expect((&AzureManagedClusterReconciler{
    54  		Client:   testEnv,
    55  		Recorder: testEnv.GetEventRecorderFor("azuremanagedcluster-reconciler"),
    56  	}).SetupWithManager(context.Background(), testEnv.Manager, Options{Options: controller.Options{MaxConcurrentReconciles: 1}})).To(Succeed())
    57  
    58  	Expect((&AzureManagedControlPlaneReconciler{
    59  		Client:   testEnv,
    60  		Recorder: testEnv.GetEventRecorderFor("azuremanagedcontrolplane-reconciler"),
    61  	}).SetupWithManager(context.Background(), testEnv.Manager, Options{Options: controller.Options{MaxConcurrentReconciles: 1}})).To(Succeed())
    62  
    63  	Expect(NewAzureManagedMachinePoolReconciler(testEnv, testEnv.GetEventRecorderFor("azuremanagedmachinepool-reconciler"),
    64  		reconciler.Timeouts{}, "").SetupWithManager(context.Background(), testEnv.Manager, Options{Options: controller.Options{MaxConcurrentReconciles: 1}})).To(Succeed())
    65  
    66  	// +kubebuilder:scaffold:scheme
    67  
    68  	ctx, cancel := context.WithCancel(context.Background())
    69  	testEnvCancel = cancel
    70  
    71  	By("starting the manager")
    72  	go func() {
    73  		defer GinkgoRecover()
    74  		Expect(testEnv.StartManager(ctx)).To(Succeed())
    75  	}()
    76  
    77  	Eventually(func() bool {
    78  		nodes := &corev1.NodeList{}
    79  		if err := testEnv.Client.List(context.Background(), nodes); err != nil {
    80  			return false
    81  		}
    82  		return true
    83  	}).Should(BeTrue())
    84  })
    85  
    86  var _ = AfterSuite(func() {
    87  	testEnvCancel()
    88  	if testEnv != nil {
    89  		By("tearing down the test environment")
    90  		Expect(testEnv.Stop()).To(Succeed())
    91  	}
    92  })