sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/api/v1alpha2/suite_test.go (about)

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     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 v1alpha2
    18  
    19  import (
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	. "github.com/onsi/ginkgo"
    24  	. "github.com/onsi/gomega"
    25  
    26  	"k8s.io/client-go/kubernetes/scheme"
    27  	"k8s.io/client-go/rest"
    28  	"k8s.io/klog"
    29  	"k8s.io/klog/klogr"
    30  	"sigs.k8s.io/controller-runtime/pkg/client"
    31  	"sigs.k8s.io/controller-runtime/pkg/envtest"
    32  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    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  func init() {
    43  	klog.InitFlags(nil)
    44  	klog.SetOutput(GinkgoWriter)
    45  	logf.SetLogger(klogr.New())
    46  }
    47  
    48  func TestAPIs(t *testing.T) {
    49  	RegisterFailHandler(Fail)
    50  
    51  	RunSpecsWithDefaultAndCustomReporters(t,
    52  		"v1alpha2 Suite",
    53  		[]Reporter{envtest.NewlineReporter{}})
    54  }
    55  
    56  var _ = BeforeSuite(func(done Done) {
    57  	By("bootstrapping test environment")
    58  	testEnv = &envtest.Environment{
    59  		CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
    60  	}
    61  
    62  	err := SchemeBuilder.AddToScheme(scheme.Scheme)
    63  	Expect(err).NotTo(HaveOccurred())
    64  
    65  	cfg, err = testEnv.Start()
    66  	Expect(err).ToNot(HaveOccurred())
    67  	Expect(cfg).ToNot(BeNil())
    68  
    69  	k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
    70  	Expect(err).ToNot(HaveOccurred())
    71  	Expect(k8sClient).ToNot(BeNil())
    72  
    73  	close(done)
    74  }, 60)
    75  
    76  var _ = AfterSuite(func() {
    77  	By("tearing down the test environment")
    78  	err := testEnv.Stop()
    79  	Expect(err).ToNot(HaveOccurred())
    80  })