github.com/argoproj-labs/argocd-operator@v0.10.0/controllers/suite_testx.go (about) 1 /* 2 Copyright 2021. 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 "path/filepath" 21 22 . "github.com/onsi/ginkgo" 23 . "github.com/onsi/gomega" 24 "k8s.io/client-go/kubernetes/scheme" 25 "sigs.k8s.io/controller-runtime/pkg/client" 26 "sigs.k8s.io/controller-runtime/pkg/envtest" 27 logf "sigs.k8s.io/controller-runtime/pkg/log" 28 "sigs.k8s.io/controller-runtime/pkg/log/zap" 29 30 v1alpha1 "github.com/argoproj-labs/argocd-operator/api/v1alpha1" 31 v1beta1 "github.com/argoproj-labs/argocd-operator/api/v1beta1" 32 //+kubebuilder:scaffold:imports 33 ) 34 35 // These tests use Ginkgo (BDD-style Go testing framework). Refer to 36 // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. 37 38 // var cfg *rest.Config 39 var k8sClient client.Client 40 var testEnv *envtest.Environment 41 42 var _ = BeforeSuite(func() { 43 logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) 44 45 By("bootstrapping test environment") 46 testEnv = &envtest.Environment{ 47 CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, 48 ErrorIfCRDPathMissing: true, 49 } 50 51 cfg, err := testEnv.Start() 52 Expect(err).NotTo(HaveOccurred()) 53 Expect(cfg).NotTo(BeNil()) 54 55 err = v1alpha1.AddToScheme(scheme.Scheme) 56 Expect(err).NotTo(HaveOccurred()) 57 58 err = v1beta1.AddToScheme(scheme.Scheme) 59 Expect(err).NotTo(HaveOccurred()) 60 61 //+kubebuilder:scaffold:scheme 62 63 k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) 64 Expect(err).NotTo(HaveOccurred()) 65 Expect(k8sClient).NotTo(BeNil()) 66 67 }, 60) 68 69 var _ = AfterSuite(func() { 70 By("tearing down the test environment") 71 err := testEnv.Stop() 72 Expect(err).NotTo(HaveOccurred()) 73 })