github.com/redhat-appstudio/release-service@v0.0.0-20240507143925-083712697924/api/v1alpha1/suite_test.go (about)

     1  /*
     2  Copyright 2022.
     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 v1alpha1
    18  
    19  import (
    20  	. "github.com/onsi/ginkgo/v2"
    21  	. "github.com/onsi/gomega"
    22  	"path/filepath"
    23  	"testing"
    24  
    25  	"sigs.k8s.io/controller-runtime/pkg/envtest"
    26  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    27  	"sigs.k8s.io/controller-runtime/pkg/log/zap"
    28  )
    29  
    30  // These tests use Ginkgo (BDD-style Go testing framework). Refer to
    31  // http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
    32  
    33  var testEnv *envtest.Environment
    34  
    35  func Test(t *testing.T) {
    36  	RegisterFailHandler(Fail)
    37  	RunSpecs(t, "APIs Suite")
    38  }
    39  
    40  var _ = BeforeSuite(func() {
    41  	logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
    42  
    43  	By("bootstrapping test environment")
    44  	testEnv = &envtest.Environment{
    45  		CRDDirectoryPaths:     []string{filepath.Join("..", "..", "config", "crd", "bases")},
    46  		ErrorIfCRDPathMissing: false,
    47  	}
    48  
    49  	cfg, err := testEnv.Start()
    50  	Expect(err).NotTo(HaveOccurred())
    51  	Expect(cfg).NotTo(BeNil())
    52  })
    53  
    54  var _ = AfterSuite(func() {
    55  	By("tearing down the test environment")
    56  	err := testEnv.Stop()
    57  	Expect(err).NotTo(HaveOccurred())
    58  })