github.com/IBM-Blockchain/fabric-operator@v1.0.4/controllers/suite_test.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package controllers 20 21 import ( 22 "path/filepath" 23 "testing" 24 25 . "github.com/onsi/ginkgo/v2" 26 . "github.com/onsi/gomega" 27 "k8s.io/client-go/kubernetes/scheme" 28 "k8s.io/client-go/rest" 29 "sigs.k8s.io/controller-runtime/pkg/client" 30 "sigs.k8s.io/controller-runtime/pkg/envtest" 31 logf "sigs.k8s.io/controller-runtime/pkg/log" 32 "sigs.k8s.io/controller-runtime/pkg/log/zap" 33 34 ibpv1beta1 "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 35 // +kubebuilder:scaffold:imports 36 ) 37 38 // These tests use Ginkgo (BDD-style Go testing framework). Refer to 39 // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. 40 41 var cfg *rest.Config 42 var k8sClient client.Client 43 var testEnv *envtest.Environment 44 45 func TestAPIs(t *testing.T) { 46 RegisterFailHandler(Fail) 47 } 48 49 var _ = BeforeSuite(func() { 50 logf.SetLogger(zap.New()) 51 52 By("bootstrapping test environment") 53 testEnv = &envtest.Environment{ 54 CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, 55 } 56 57 var err error 58 cfg, err = testEnv.Start() 59 Expect(err).ToNot(HaveOccurred()) 60 Expect(cfg).ToNot(BeNil()) 61 62 err = ibpv1beta1.AddToScheme(scheme.Scheme) 63 Expect(err).NotTo(HaveOccurred()) 64 65 err = ibpv1beta1.AddToScheme(scheme.Scheme) 66 Expect(err).NotTo(HaveOccurred()) 67 68 err = ibpv1beta1.AddToScheme(scheme.Scheme) 69 Expect(err).NotTo(HaveOccurred()) 70 71 err = ibpv1beta1.AddToScheme(scheme.Scheme) 72 Expect(err).NotTo(HaveOccurred()) 73 74 // +kubebuilder:scaffold:scheme 75 76 k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) 77 Expect(err).ToNot(HaveOccurred()) 78 Expect(k8sClient).ToNot(BeNil()) 79 }) 80 81 var _ = AfterSuite(func() { 82 By("tearing down the test environment") 83 err := testEnv.Stop() 84 Expect(err).ToNot(HaveOccurred()) 85 })