diff --git a/bootstrap/kubeadm/api/v1alpha2/kubeadmbootstrapconfig_types_test.go b/bootstrap/kubeadm/api/v1alpha2/kubeadmbootstrapconfig_types_test.go deleted file mode 100644 index 47915b61bdb3..000000000000 --- a/bootstrap/kubeadm/api/v1alpha2/kubeadmbootstrapconfig_types_test.go +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha2 - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "golang.org/x/net/context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -// These tests are written in BDD-style using Ginkgo framework. Refer to -// http://onsi.github.io/ginkgo to learn more. - -var _ = Describe("KubeadmConfig", func() { - var ( - key types.NamespacedName - created, fetched *KubeadmConfig - ) - - BeforeEach(func() { - // Add any setup steps that needs to be executed before each test - }) - - AfterEach(func() { - // Add any teardown steps that needs to be executed after each test - }) - - // Add Tests for OpenAPI validation (or additional CRD features) specified in - // your API definition. - // Avoid adding tests for vanilla CRUD operations because they would - // test Kubernetes API server, which isn't the goal here. - Context("Create API", func() { - - It("should create an object successfully", func() { - - key = types.NamespacedName{ - Name: "foo", - Namespace: "default", - } - created = &KubeadmConfig{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "default", - }, - } - - By("creating an API obj") - Expect(k8sClient.Create(context.TODO(), created)).To(Succeed()) - - fetched = &KubeadmConfig{} - Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed()) - Expect(fetched).To(Equal(created)) - - By("deleting the created object") - Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed()) - Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed()) - }) - - }) - -}) diff --git a/bootstrap/kubeadm/api/v1alpha2/suite_test.go b/bootstrap/kubeadm/api/v1alpha2/suite_test.go deleted file mode 100644 index e7531d9a42c5..000000000000 --- a/bootstrap/kubeadm/api/v1alpha2/suite_test.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha2 - -import ( - "path/filepath" - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "k8s.io/klog" - "k8s.io/klog/klogr" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - logf "sigs.k8s.io/controller-runtime/pkg/log" -) - -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment - -func init() { - klog.InitFlags(nil) - klog.SetOutput(GinkgoWriter) - logf.SetLogger(klogr.New()) -} - -func TestAPIs(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecsWithDefaultAndCustomReporters(t, - "v1alpha2 Suite", - []Reporter{printer.NewlineReporter{}}) -} - -var _ = BeforeSuite(func(done Done) { - By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{ - filepath.Join("..", "..", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "..", "controlplane", "kubeadm", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "..", "config", "crd", "bases"), - }, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - cfg, err = testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).ToNot(HaveOccurred()) - Expect(k8sClient).ToNot(BeNil()) - - close(done) -}, 60) - -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) -}) diff --git a/bootstrap/kubeadm/api/v1alpha3/suite_test.go b/bootstrap/kubeadm/api/v1alpha3/suite_test.go index 07739b0dace4..ea0e5b0dcc9f 100644 --- a/bootstrap/kubeadm/api/v1alpha3/suite_test.go +++ b/bootstrap/kubeadm/api/v1alpha3/suite_test.go @@ -17,35 +17,17 @@ limitations under the License. package v1alpha3 import ( - "path/filepath" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "k8s.io/klog" - "k8s.io/klog/klogr" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - logf "sigs.k8s.io/controller-runtime/pkg/log" ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment - -func init() { - klog.InitFlags(nil) - klog.SetOutput(GinkgoWriter) - logf.SetLogger(klogr.New()) -} - func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) @@ -53,33 +35,3 @@ func TestAPIs(t *testing.T) { "v1alpha3 Suite", []Reporter{printer.NewlineReporter{}}) } - -var _ = BeforeSuite(func(done Done) { - By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{ - filepath.Join("..", "..", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "..", "controlplane", "kubeadm", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "..", "config", "crd", "bases"), - }, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - cfg, err = testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).ToNot(HaveOccurred()) - Expect(k8sClient).ToNot(BeNil()) - - close(done) -}, 60) - -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) -}) diff --git a/bootstrap/kubeadm/controllers/kubeadmconfig_controller_reconciler_test.go b/bootstrap/kubeadm/controllers/kubeadmconfig_controller_reconciler_test.go index 0effbfa0081e..fc1f7d232644 100644 --- a/bootstrap/kubeadm/controllers/kubeadmconfig_controller_reconciler_test.go +++ b/bootstrap/kubeadm/controllers/kubeadmconfig_controller_reconciler_test.go @@ -36,17 +36,17 @@ var _ = Describe("KubeadmConfigReconciler", func() { Context("Reconcile a KubeadmConfig", func() { It("should wait until infrastructure is ready", func() { cluster := newCluster("cluster1") - Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) + Expect(testEnv.Create(context.Background(), cluster)).To(Succeed()) machine := newMachine(cluster, "my-machine") - Expect(k8sClient.Create(context.Background(), machine)).To(Succeed()) + Expect(testEnv.Create(context.Background(), machine)).To(Succeed()) config := newKubeadmConfig(machine, "my-machine-config") - Expect(k8sClient.Create(context.Background(), config)).To(Succeed()) + Expect(testEnv.Create(context.Background(), config)).To(Succeed()) reconciler := KubeadmConfigReconciler{ Log: log.Log, - Client: k8sClient, + Client: testEnv, } By("Calling reconcile should requeue") result, err := reconciler.Reconcile(ctrl.Request{ diff --git a/bootstrap/kubeadm/controllers/suite_test.go b/bootstrap/kubeadm/controllers/suite_test.go index eb4919e3c015..f64120b0d38c 100644 --- a/bootstrap/kubeadm/controllers/suite_test.go +++ b/bootstrap/kubeadm/controllers/suite_test.go @@ -17,35 +17,22 @@ limitations under the License. package controllers import ( - "path/filepath" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/klog" - "k8s.io/klog/klogr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" - bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" + "sigs.k8s.io/cluster-api/test/helpers" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - logf "sigs.k8s.io/controller-runtime/pkg/log" // +kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var k8sClient client.Client -var testEnv *envtest.Environment - -func init() { - klog.InitFlags(nil) - klog.SetOutput(GinkgoWriter) - logf.SetLogger(klogr.New()) -} +var ( + testEnv *helpers.TestEnvironment +) func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) @@ -57,31 +44,20 @@ func TestAPIs(t *testing.T) { var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{ - filepath.Join("..", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "controlplane", "kubeadm", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "config", "crd", "bases"), - }, - } + testEnv = helpers.NewTestEnvironment() - cfg, err := testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - Expect(bootstrapv1.AddToScheme(scheme.Scheme)).NotTo(HaveOccurred()) - Expect(clusterv1.AddToScheme(scheme.Scheme)).NotTo(HaveOccurred()) - // +kubebuilder:scaffold:scheme - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).ToNot(HaveOccurred()) - Expect(k8sClient).ToNot(BeNil()) + By("starting the manager") + go func() { + defer GinkgoRecover() + Expect(testEnv.StartManager()).To(Succeed()) + }() close(done) }, 60) var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) + if testEnv != nil { + By("tearing down the test environment") + Expect(testEnv.Stop()).To(Succeed()) + } }) diff --git a/bootstrap/kubeadm/internal/locking/control_plane_init_mutex_test.go b/bootstrap/kubeadm/internal/locking/control_plane_init_mutex_test.go index 4b777680eb6b..a9f0c8932892 100644 --- a/bootstrap/kubeadm/internal/locking/control_plane_init_mutex_test.go +++ b/bootstrap/kubeadm/internal/locking/control_plane_init_mutex_test.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/klog" clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" @@ -44,10 +43,6 @@ const ( clusterNamespace = "test-namespace" ) -func init() { - klog.InitFlags(nil) -} - func TestControlPlaneInitMutex_Lock(t *testing.T) { g := NewWithT(t) diff --git a/controllers/remote/cluster_cache_healthcheck_test.go b/controllers/remote/cluster_cache_healthcheck_test.go index 58934a5df1d5..01d2698d56aa 100644 --- a/controllers/remote/cluster_cache_healthcheck_test.go +++ b/controllers/remote/cluster_cache_healthcheck_test.go @@ -54,7 +54,7 @@ var _ = Describe("ClusterCache HealthCheck suite", func() { BeforeEach(func() { By("Setting up a new manager") var err error - mgr, err = manager.New(cfg, manager.Options{ + mgr, err = manager.New(testEnv.Config, manager.Options{ Scheme: scheme.Scheme, MetricsBindAddress: "0", }) @@ -86,7 +86,7 @@ var _ = Describe("ClusterCache HealthCheck suite", func() { Expect(k8sClient.Create(ctx, testCluster)).To(Succeed()) By("Creating a test cluster kubeconfig") - Expect(kubeconfig.CreateEnvTestSecret(k8sClient, cfg, testCluster)).To(Succeed()) + Expect(kubeconfig.CreateEnvTestSecret(k8sClient, testEnv.Config, testCluster)).To(Succeed()) testClusterKey = util.ObjectKey(testCluster) @@ -109,7 +109,7 @@ var _ = Describe("ClusterCache HealthCheck suite", func() { // Ensure the context times out after the consistently below ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() - config := rest.CopyConfig(cfg) + config := rest.CopyConfig(testEnv.Config) go cct.healthCheckCluster(&healthCheckInput{ctx.Done(), testClusterKey, config, testPollInterval, testPollTimeout, testUnhealthyThreshold, "/"}) // This should succed after 1 second, approx 10 requests to the API @@ -128,7 +128,7 @@ var _ = Describe("ClusterCache HealthCheck suite", func() { It("with an invalid path", func() { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() - config := rest.CopyConfig(cfg) + config := rest.CopyConfig(testEnv.Config) go cct.healthCheckCluster(&healthCheckInput{ctx.Done(), testClusterKey, config, testPollInterval, testPollTimeout, testUnhealthyThreshold, "/foo"}) // This should succeed after 3 consecutive failed requests @@ -147,7 +147,7 @@ var _ = Describe("ClusterCache HealthCheck suite", func() { It("with an invalid config", func() { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() - config := rest.CopyConfig(cfg) + config := rest.CopyConfig(testEnv.Config) // Set the host to a random free port on localhost addr, err := net.ResolveTCPAddr("tcp", "localhost:0") diff --git a/controllers/remote/cluster_cache_reconciler_test.go b/controllers/remote/cluster_cache_reconciler_test.go index 0ecdd1bcdc42..1b360fa405e5 100644 --- a/controllers/remote/cluster_cache_reconciler_test.go +++ b/controllers/remote/cluster_cache_reconciler_test.go @@ -68,7 +68,7 @@ var _ = Describe("ClusterCache Reconciler suite", func() { }, timeout).Should(Succeed()) By("Creating a test cluster kubeconfig") - Expect(kubeconfig.CreateEnvTestSecret(k8sClient, cfg, testCluster)).To(Succeed()) + Expect(kubeconfig.CreateEnvTestSecret(k8sClient, testEnv.Config, testCluster)).To(Succeed()) // Check the secret can be fetch from the API server secretKey := client.ObjectKey{Namespace: testNamespace.GetName(), Name: fmt.Sprintf("%s-kubeconfig", testCluster.GetName())} Eventually(func() error { @@ -106,7 +106,7 @@ var _ = Describe("ClusterCache Reconciler suite", func() { BeforeEach(func() { By("Setting up a new manager") var err error - mgr, err = manager.New(cfg, manager.Options{ + mgr, err = manager.New(testEnv.Config, manager.Options{ Scheme: scheme.Scheme, MetricsBindAddress: "0", }) diff --git a/controllers/remote/cluster_cache_tracker_test.go b/controllers/remote/cluster_cache_tracker_test.go index 3b0b450feedf..1a83da55c32e 100644 --- a/controllers/remote/cluster_cache_tracker_test.go +++ b/controllers/remote/cluster_cache_tracker_test.go @@ -122,7 +122,7 @@ var _ = Describe("ClusterCache Tracker suite", func() { BeforeEach(func() { By("Setting up a new manager") var err error - mgr, err = manager.New(cfg, manager.Options{ + mgr, err = manager.New(testEnv.Config, manager.Options{ Scheme: scheme.Scheme, MetricsBindAddress: "0", }) @@ -154,7 +154,7 @@ var _ = Describe("ClusterCache Tracker suite", func() { Expect(k8sClient.Create(ctx, testCluster)).To(Succeed()) By("Creating a test cluster kubeconfig") - Expect(kubeconfig.CreateEnvTestSecret(k8sClient, cfg, testCluster)).To(Succeed()) + Expect(kubeconfig.CreateEnvTestSecret(k8sClient, testEnv.Config, testCluster)).To(Succeed()) testClusterKey := util.ObjectKey(testCluster) watcher, watcherInfo := newTestWatcher() @@ -306,7 +306,7 @@ var _ = Describe("ClusterCache Tracker suite", func() { Expect(k8sClient.Create(ctx, testCluster)).To(Succeed()) By("Creating a test cluster kubeconfig") - Expect(kubeconfig.CreateEnvTestSecret(k8sClient, cfg, testCluster)).To(Succeed()) + Expect(kubeconfig.CreateEnvTestSecret(k8sClient, testEnv.Config, testCluster)).To(Succeed()) // Check the secret can be fetch from the API server secretKey := client.ObjectKey{Namespace: testNamespace.GetName(), Name: fmt.Sprintf("%s-kubeconfig", testCluster.GetName())} Eventually(func() error { diff --git a/controllers/remote/suite_test.go b/controllers/remote/suite_test.go index 93722fc3a266..13e7d6c4f667 100644 --- a/controllers/remote/suite_test.go +++ b/controllers/remote/suite_test.go @@ -18,54 +18,32 @@ package remote import ( "context" - "flag" - "path/filepath" "testing" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "k8s.io/klog" - "k8s.io/klog/klogr" - "sigs.k8s.io/controller-runtime/pkg/envtest" + "sigs.k8s.io/cluster-api/test/helpers" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - logf "sigs.k8s.io/controller-runtime/pkg/log" - - clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" // +kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -func init() { - klog.InitFlags(nil) - logf.SetLogger(klogr.New()) - - // Register required object kinds with global scheme. - _ = clusterv1.AddToScheme(scheme.Scheme) -} - const ( timeout = time.Second * 10 ) var ( - cfg *rest.Config - testEnv *envtest.Environment + testEnv *helpers.TestEnvironment ctx = context.Background() ) func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) - Expect(flag.Set("logtostderr", "false")).To(Succeed()) - flag.Parse() - klog.SetOutput(GinkgoWriter) - RunSpecsWithDefaultAndCustomReporters(t, "Controller Suite", []Reporter{printer.NewlineReporter{}}) @@ -73,19 +51,20 @@ func TestAPIs(t *testing.T) { var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, - } + testEnv = helpers.NewTestEnvironment() - var err error - cfg, err = testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) + By("starting the manager") + go func() { + defer GinkgoRecover() + Expect(testEnv.StartManager()).To(Succeed()) + }() close(done) }, 60) var _ = AfterSuite(func() { - By("tearing down the test environment") - Expect(testEnv.Stop()).To(Succeed()) + if testEnv != nil { + By("tearing down the test environment") + Expect(testEnv.Stop()).To(Succeed()) + } }) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index eb678b3e860a..6dcdff0db534 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -24,8 +24,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "k8s.io/klog" - "k8s.io/klog/klogr" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" @@ -38,11 +36,6 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -func init() { - klog.InitFlags(nil) - log.SetLogger(klogr.New()) -} - const ( timeout = time.Second * 10 ) @@ -63,9 +56,7 @@ func TestAPIs(t *testing.T) { var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") - var err error - testEnv, err = helpers.NewTestEnvironment() - Expect(err).NotTo(HaveOccurred()) + testEnv = helpers.NewTestEnvironment() // Set up a ClusterCacheTracker and ClusterCacheReconciler to provide to controllers // requiring a connection to a remote cluster @@ -111,6 +102,7 @@ var _ = BeforeSuite(func(done Done) { By("starting the manager") go func() { + defer GinkgoRecover() Expect(testEnv.StartManager()).To(Succeed()) }() diff --git a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_types_test.go b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_types_test.go deleted file mode 100644 index 82890951dfe3..000000000000 --- a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_types_test.go +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha3 - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - - "golang.org/x/net/context" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3" -) - -// These tests are written in BDD-style using Ginkgo framework. Refer to -// http://onsi.github.io/ginkgo to learn more. - -var _ = Describe("KubeadmControlPlane", func() { - var ( - key types.NamespacedName - created, fetched *KubeadmControlPlane - ctx = context.TODO() - ) - - // Add Tests for OpenAPI validation (or additional CRD features) specified in - // your API definition. - // Avoid adding tests for vanilla CRUD operations because they would - // test Kubernetes API server, which isn't the goal here. - Context("Create API", func() { - - It("should create an object successfully", func() { - - key = types.NamespacedName{ - Name: "foo", - Namespace: "default", - } - - // missing field - created2 := map[string]interface{}{ - "kind": "KubeadmControlPlane", - "apiVersion": "controlplane.cluster.x-k8s.io/v1alpha3", - "metadata": map[string]interface{}{ - "name": "foo", - "namespace": "default", - }, - "spec": map[string]interface{}{ - "version": "v1.1.1", - }, - } - createdUnstructured := &unstructured.Unstructured{Object: created2} - - By("creating an API obj with missing field") - Expect(k8sClient.Create(ctx, createdUnstructured)).NotTo(Succeed()) - - created = &KubeadmControlPlane{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "default", - }, - Spec: KubeadmControlPlaneSpec{ - InfrastructureTemplate: corev1.ObjectReference{}, - Version: "v1.1.1", - KubeadmConfigSpec: cabpkv1.KubeadmConfigSpec{}, - }, - } - - By("creating an API obj") - Expect(k8sClient.Create(ctx, created)).To(Succeed()) - - fetched = &KubeadmControlPlane{} - Expect(k8sClient.Get(ctx, key, fetched)).To(Succeed()) - Expect(fetched).To(Equal(created)) - - By("deleting the created object") - Expect(k8sClient.Delete(ctx, created)).To(Succeed()) - Expect(k8sClient.Get(ctx, key, created)).ToNot(Succeed()) - }) - - }) -}) diff --git a/controlplane/kubeadm/api/v1alpha3/suite_test.go b/controlplane/kubeadm/api/v1alpha3/suite_test.go deleted file mode 100644 index 2881e158e173..000000000000 --- a/controlplane/kubeadm/api/v1alpha3/suite_test.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha3 - -import ( - "path/filepath" - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "k8s.io/klog" - "k8s.io/klog/klogr" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - logf "sigs.k8s.io/controller-runtime/pkg/log" -) - -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment - -func init() { - klog.InitFlags(nil) - klog.SetOutput(GinkgoWriter) - logf.SetLogger(klogr.New()) -} - -func TestAPIs(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecsWithDefaultAndCustomReporters(t, - "v1alpha3 Suite", - []Reporter{printer.NewlineReporter{}}) -} - -var _ = BeforeSuite(func(done Done) { - By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{ - filepath.Join("..", "..", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "..", "bootstrap", "kubeadm", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "..", "config", "crd", "bases"), - }, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) - - cfg, err = testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).ToNot(HaveOccurred()) - Expect(k8sClient).ToNot(BeNil()) - - close(done) -}, 60) - -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) -}) diff --git a/controlplane/kubeadm/controllers/controller_test.go b/controlplane/kubeadm/controllers/controller_test.go index 5ef4a126d50e..2fe0e00c9560 100644 --- a/controlplane/kubeadm/controllers/controller_test.go +++ b/controlplane/kubeadm/controllers/controller_test.go @@ -60,7 +60,7 @@ var _ = Describe("KubeadmControlPlaneReconciler", func() { Context("Reconcile a KubeadmControlPlane", func() { It("should return error if owner cluster is missing", func() { - clusterName, clusterNamespace := "foo", "default" + clusterName, clusterNamespace := "foo-1", "default" cluster := newCluster(&types.NamespacedName{Name: clusterName, Namespace: clusterNamespace}) kcp := &controlplanev1.KubeadmControlPlane{ @@ -83,11 +83,11 @@ var _ = Describe("KubeadmControlPlaneReconciler", func() { kcp.Default() - Expect(k8sClient.Create(context.Background(), kcp)).To(Succeed()) - Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) + Expect(testEnv.Create(context.Background(), kcp)).To(Succeed()) + Expect(testEnv.Create(context.Background(), cluster)).To(Succeed()) r := &KubeadmControlPlaneReconciler{ - Client: k8sClient, + Client: testEnv, Log: log.Log, recorder: record.NewFakeRecorder(32), } @@ -97,12 +97,12 @@ var _ = Describe("KubeadmControlPlaneReconciler", func() { Expect(result).To(Equal(ctrl.Result{})) By("Calling reconcile should return error") - Expect(k8sClient.Delete(context.Background(), cluster)).To(Succeed()) + Expect(testEnv.Delete(context.Background(), cluster)).To(Succeed()) - result, err = r.Reconcile(ctrl.Request{NamespacedName: util.ObjectKey(kcp)}) - - Expect(err).To(HaveOccurred()) - Expect(result.Requeue).To(BeFalse()) + Eventually(func() error { + _, err := r.Reconcile(ctrl.Request{NamespacedName: util.ObjectKey(kcp)}) + return err + }, 10*time.Second).Should(HaveOccurred()) }) }) }) diff --git a/controlplane/kubeadm/controllers/suite_test.go b/controlplane/kubeadm/controllers/suite_test.go index 51f880d0d98f..f64120b0d38c 100644 --- a/controlplane/kubeadm/controllers/suite_test.go +++ b/controlplane/kubeadm/controllers/suite_test.go @@ -17,35 +17,22 @@ limitations under the License. package controllers import ( - "path/filepath" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/klog" - "k8s.io/klog/klogr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" - controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1alpha3" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" + "sigs.k8s.io/cluster-api/test/helpers" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - logf "sigs.k8s.io/controller-runtime/pkg/log" // +kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var k8sClient client.Client -var testEnv *envtest.Environment - -func init() { - klog.InitFlags(nil) - klog.SetOutput(GinkgoWriter) - logf.SetLogger(klogr.New()) -} +var ( + testEnv *helpers.TestEnvironment +) func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) @@ -57,31 +44,20 @@ func TestAPIs(t *testing.T) { var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{ - filepath.Join("..", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "bootstrap", "kubeadm", "config", "crd", "bases"), - filepath.Join("..", "..", "..", "config", "crd", "bases"), - }, - } + testEnv = helpers.NewTestEnvironment() - cfg, err := testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - Expect(controlplanev1.AddToScheme(scheme.Scheme)).To(Succeed()) - Expect(clusterv1.AddToScheme(scheme.Scheme)).To(Succeed()) - // +kubebuilder:scaffold:scheme - - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).ToNot(HaveOccurred()) - Expect(k8sClient).ToNot(BeNil()) + By("starting the manager") + go func() { + defer GinkgoRecover() + Expect(testEnv.StartManager()).To(Succeed()) + }() close(done) }, 60) var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).ToNot(HaveOccurred()) + if testEnv != nil { + By("tearing down the test environment") + Expect(testEnv.Stop()).To(Succeed()) + } }) diff --git a/exp/controllers/machinepool_controller_phases_test.go b/exp/controllers/machinepool_controller_phases_test.go index 1f11bc0bf94b..d37ce4e31105 100644 --- a/exp/controllers/machinepool_controller_phases_test.go +++ b/exp/controllers/machinepool_controller_phases_test.go @@ -109,7 +109,7 @@ var _ = Describe("Reconcile MachinePool Phases", func() { } BeforeEach(func() { - defaultKubeconfigSecret = kubeconfig.GenerateSecret(defaultCluster, kubeconfig.FromEnvTestConfig(cfg, defaultCluster)) + defaultKubeconfigSecret = kubeconfig.GenerateSecret(defaultCluster, kubeconfig.FromEnvTestConfig(testEnv.Config, defaultCluster)) }) It("Should set OwnerReference and cluster name label on external objects", func() { diff --git a/exp/controllers/suite_test.go b/exp/controllers/suite_test.go index 3f40b8db21e6..cb70af6a419d 100644 --- a/exp/controllers/suite_test.go +++ b/exp/controllers/suite_test.go @@ -18,53 +18,25 @@ package controllers import ( "context" - "path/filepath" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "k8s.io/klog" - "k8s.io/klog/klogr" - "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" "sigs.k8s.io/controller-runtime/pkg/log" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/manager" - clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" - "sigs.k8s.io/cluster-api/controllers/external" - expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha3" - "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/test/helpers" // +kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -func init() { - klog.InitFlags(nil) - logf.SetLogger(klogr.New()) - - // Register required object kinds with global scheme. - _ = apiextensionsv1.AddToScheme(scheme.Scheme) - _ = clusterv1.AddToScheme(scheme.Scheme) - _ = expv1.AddToScheme(scheme.Scheme) -} - var ( - cfg *rest.Config - k8sClient client.Client - testEnv *envtest.Environment - mgr manager.Manager - doneMgr = make(chan struct{}) - ctx = context.Background() + testEnv *helpers.TestEnvironment + ctx = context.Background() ) func TestAPIs(t *testing.T) { @@ -77,50 +49,26 @@ func TestAPIs(t *testing.T) { var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDs: []runtime.Object{ - external.TestGenericBootstrapCRD.DeepCopy(), - external.TestGenericBootstrapTemplateCRD.DeepCopy(), - external.TestGenericInfrastructureCRD.DeepCopy(), - external.TestGenericInfrastructureTemplateCRD.DeepCopy(), - }, - CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, - } - - var err error - cfg, err = testEnv.Start() - Expect(err).ToNot(HaveOccurred()) - Expect(cfg).ToNot(BeNil()) - - // +kubebuilder:scaffold:scheme - - By("setting up a new manager") - mgr, err = manager.New(cfg, manager.Options{ - Scheme: scheme.Scheme, - MetricsBindAddress: "0", - NewClient: util.ManagerDelegatingClientFunc, - }) - Expect(err).NotTo(HaveOccurred()) - - k8sClient = mgr.GetClient() + testEnv = helpers.NewTestEnvironment() Expect((&MachinePoolReconciler{ - Client: k8sClient, + Client: testEnv, Log: log.Log, - recorder: mgr.GetEventRecorderFor("machinepool-controller"), - }).SetupWithManager(mgr, controller.Options{MaxConcurrentReconciles: 1})).To(Succeed()) + recorder: testEnv.GetEventRecorderFor("machinepool-controller"), + }).SetupWithManager(testEnv.Manager, controller.Options{MaxConcurrentReconciles: 1})).To(Succeed()) By("starting the manager") go func() { - Expect(mgr.Start(doneMgr)).To(Succeed()) + defer GinkgoRecover() + Expect(testEnv.StartManager()).To(Succeed()) }() close(done) }, 60) var _ = AfterSuite(func() { - By("closing the manager") - close(doneMgr) - By("tearing down the test environment") - Expect(testEnv.Stop()).To(Succeed()) + if testEnv != nil { + By("tearing down the test environment") + Expect(testEnv.Stop()).To(Succeed()) + } }) diff --git a/go.mod b/go.mod index a38b73a1fdda..f2903ef109f3 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.6.2 go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 - golang.org/x/net v0.0.0-20200301022130-244492dfa37a + golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d google.golang.org/appengine v1.6.6 // indirect google.golang.org/grpc v1.26.0 diff --git a/scripts/ci-test.sh b/scripts/ci-test.sh index 97c7719d6bda..1909363f670c 100755 --- a/scripts/ci-test.sh +++ b/scripts/ci-test.sh @@ -24,9 +24,10 @@ cd "${REPO_ROOT}" || exit 1 # shellcheck source=./hack/ensure-go.sh source "${REPO_ROOT}/hack/ensure-go.sh" -make generate test +echo "*** Testing Cluster API ***" +make test -echo "*** Testing Cluster API Provider Docker ***" +echo -e "\n*** Testing Cluster API Provider Docker ***\n" # Docker provider cd test/infrastructure/docker -make generate test +make test diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index 8317b976c221..2245c6078bb7 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -21,15 +21,19 @@ import ( "path/filepath" goruntime "runtime" + "github.com/onsi/ginkgo" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" - kerrors "k8s.io/apimachinery/pkg/util/errors" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + "k8s.io/klog" + "k8s.io/klog/klogr" clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3" + "sigs.k8s.io/cluster-api/cmd/clusterctl/log" "sigs.k8s.io/cluster-api/controllers/external" + expv1 "sigs.k8s.io/cluster-api/exp/api/v1alpha3" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/kubeconfig" "sigs.k8s.io/controller-runtime/pkg/client" @@ -37,70 +41,77 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" ) -type TestEnvironment struct { - *envtest.Environment - manager.Manager - client.Client - - Config *rest.Config - scheme *runtime.Scheme - doneMgr chan struct{} +func init() { + klog.InitFlags(nil) + log.SetLogger(klogr.New()) + klog.SetOutput(ginkgo.GinkgoWriter) } -func newTestEnvironment() *TestEnvironment { - scheme := scheme.Scheme - utilruntime.Must(apiextensionsv1.AddToScheme(scheme)) - utilruntime.Must(clusterv1.AddToScheme(scheme)) - utilruntime.Must(bootstrapv1.AddToScheme(scheme)) +var ( + env *envtest.Environment +) +func init() { + // Calculate the scheme. + utilruntime.Must(apiextensionsv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(bootstrapv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(expv1.AddToScheme(scheme.Scheme)) + + // Get the root of the current file to use in CRD paths. _, filename, _, _ := goruntime.Caller(0) //nolint root := path.Join(path.Dir(filename), "..", "..") - return &TestEnvironment{ - Environment: &envtest.Environment{ - ErrorIfCRDPathMissing: true, - CRDDirectoryPaths: []string{ - filepath.Join(root, "config", "crd", "bases"), - filepath.Join(root, "controlplane", "kubeadm", "config", "crd", "bases"), - filepath.Join(root, "bootstrap", "kubeadm", "config", "crd", "bases"), - }, - CRDs: []runtime.Object{ - external.TestGenericBootstrapCRD.DeepCopy(), - external.TestGenericBootstrapTemplateCRD.DeepCopy(), - external.TestGenericInfrastructureCRD.DeepCopy(), - external.TestGenericInfrastructureTemplateCRD.DeepCopy(), - }, + // Create the test environment. + env = &envtest.Environment{ + ErrorIfCRDPathMissing: true, + CRDDirectoryPaths: []string{ + filepath.Join(root, "config", "crd", "bases"), + filepath.Join(root, "controlplane", "kubeadm", "config", "crd", "bases"), + filepath.Join(root, "bootstrap", "kubeadm", "config", "crd", "bases"), + }, + CRDs: []runtime.Object{ + external.TestGenericBootstrapCRD.DeepCopy(), + external.TestGenericBootstrapTemplateCRD.DeepCopy(), + external.TestGenericInfrastructureCRD.DeepCopy(), + external.TestGenericInfrastructureTemplateCRD.DeepCopy(), }, - scheme: scheme, - doneMgr: make(chan struct{}), } } -func NewTestEnvironment() (*TestEnvironment, error) { - env := newTestEnvironment() +// TestEnvironment encapsulates a Kubernetes local test environment. +type TestEnvironment struct { + manager.Manager + client.Client + Config *rest.Config - cfg, err := env.Environment.Start() - if err != nil { - return env, err + doneMgr chan struct{} +} + +// NewTestEnvironment creates a new environment spinning up a local api-server. +// +// This function should be called only once for each package you're running tests within, +// usually the environment is initialized in a suite_test.go file within a `BeforeSuite` ginkgo block. +func NewTestEnvironment() *TestEnvironment { + if _, err := env.Start(); err != nil { + panic(err) } - mgr, err := manager.New(cfg, manager.Options{ - Scheme: env.scheme, + mgr, err := manager.New(env.Config, manager.Options{ + Scheme: scheme.Scheme, MetricsBindAddress: "0", NewClient: util.ManagerDelegatingClientFunc, }) if err != nil { - if stopErr := env.Stop(); err != nil { - return nil, kerrors.NewAggregate([]error{err, stopErr}) - } - return env, err + klog.Fatalf("Failed to start testenv manager: %v", err) } - env.Config = cfg - env.Manager = mgr - env.Client = mgr.GetClient() - - return env, nil + return &TestEnvironment{ + Manager: mgr, + Client: mgr.GetClient(), + Config: mgr.GetConfig(), + doneMgr: make(chan struct{}), + } } func (t *TestEnvironment) StartManager() error { @@ -108,8 +119,8 @@ func (t *TestEnvironment) StartManager() error { } func (t *TestEnvironment) Stop() error { - close(t.doneMgr) - return t.Environment.Stop() + t.doneMgr <- struct{}{} + return env.Stop() } func (t *TestEnvironment) CreateKubeconfigSecret(cluster *clusterv1.Cluster) error { diff --git a/test/infrastructure/docker/controllers/dockermachine_controller_test.go b/test/infrastructure/docker/controllers/dockermachine_controller_test.go index cce2058cb9be..31c61d30801a 100644 --- a/test/infrastructure/docker/controllers/dockermachine_controller_test.go +++ b/test/infrastructure/docker/controllers/dockermachine_controller_test.go @@ -24,7 +24,6 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/klog" "k8s.io/klog/klogr" clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1alpha3" @@ -32,10 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" ) -func init() { - klog.InitFlags(nil) -} - func setupScheme() *runtime.Scheme { s := runtime.NewScheme() if err := clusterv1.AddToScheme(s); err != nil { diff --git a/util/patch/suite_test.go b/util/patch/suite_test.go index 22991fc1bd31..79eeb110383a 100644 --- a/util/patch/suite_test.go +++ b/util/patch/suite_test.go @@ -24,11 +24,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "k8s.io/klog" - "k8s.io/klog/klogr" "sigs.k8s.io/controller-runtime/pkg/envtest/printer" - "sigs.k8s.io/cluster-api/cmd/clusterctl/log" "sigs.k8s.io/cluster-api/test/helpers" // +kubebuilder:scaffold:imports ) @@ -36,13 +33,8 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -func init() { - klog.InitFlags(nil) - log.SetLogger(klogr.New()) -} - const ( - timeout = time.Second * 3 + timeout = time.Second * 10 ) var ( @@ -60,12 +52,11 @@ func TestPatch(t *testing.T) { var _ = BeforeSuite(func(done Done) { By("bootstrapping test environment") - var err error - testEnv, err = helpers.NewTestEnvironment() - Expect(err).NotTo(HaveOccurred()) + testEnv = helpers.NewTestEnvironment() By("starting the manager") go func() { + defer GinkgoRecover() Expect(testEnv.StartManager()).To(Succeed()) }()