github.com/openshift/dpu-operator@v0.0.0-20240502153209-3af840d137c2/internal/controller/suite_test.go (about)

     1  /*
     2  Copyright 2024.
     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 controller
    18  
    19  import (
    20  	"os"
    21  	"testing"
    22  
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  
    26  	"k8s.io/client-go/rest"
    27  	"sigs.k8s.io/controller-runtime/pkg/client"
    28  	"sigs.k8s.io/controller-runtime/pkg/envtest"
    29  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    30  	"sigs.k8s.io/controller-runtime/pkg/log/zap"
    31  	//+kubebuilder:scaffold:imports
    32  )
    33  
    34  // These tests use Ginkgo (BDD-style Go testing framework). Refer to
    35  // http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
    36  
    37  var cfg *rest.Config
    38  var k8sClient client.Client
    39  var testEnv *envtest.Environment
    40  
    41  func TestControllers(t *testing.T) {
    42  	RegisterFailHandler(Fail)
    43  
    44  	RunSpecs(t, "Controller Suite")
    45  }
    46  
    47  var _ = BeforeSuite(func() {
    48  	logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
    49  	// IMPORTANT: We want to be at the project root directory (please keep this mind when
    50  	// developing tests).
    51  	// Explanation: The controller manger will need to look into "bindata" to render
    52  	// the manifest files, thus the test container need to be at the correct level.
    53  	err := os.Chdir("../..")
    54  	Expect(err).NotTo(HaveOccurred())
    55  })
    56  
    57  var _ = AfterSuite(func() {
    58  	// Nothing needed
    59  })