github.com/banzaicloud/istio-operator/pkg/apis@v0.10.8/istio/v1beta1/v1beta1_suite_test.go (about)

     1  /*
     2  Copyright 2019 Banzai Cloud.
     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 v1beta1
    18  
    19  import (
    20  	"log"
    21  	"os"
    22  	"path/filepath"
    23  	"testing"
    24  
    25  	"k8s.io/client-go/kubernetes/scheme"
    26  	"k8s.io/client-go/rest"
    27  	"sigs.k8s.io/controller-runtime/pkg/client"
    28  	"sigs.k8s.io/controller-runtime/pkg/envtest"
    29  )
    30  
    31  var cfg *rest.Config
    32  var c client.Client
    33  
    34  func TestMain(m *testing.M) {
    35  	t := &envtest.Environment{
    36  		CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "base", "crds")},
    37  	}
    38  
    39  	err := SchemeBuilder.AddToScheme(scheme.Scheme)
    40  	if err != nil {
    41  		log.Fatal(err)
    42  	}
    43  
    44  	if cfg, err = t.Start(); err != nil {
    45  		log.Fatal(err)
    46  	}
    47  
    48  	if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil {
    49  		log.Fatal(err)
    50  	}
    51  
    52  	code := m.Run()
    53  	if err = t.Stop(); err != nil {
    54  		log.Fatal(err)
    55  	}
    56  	os.Exit(code)
    57  }