github.com/kubevela/workflow@v0.6.0/pkg/executor/suit_test.go (about)

     1  /*
     2  Copyright 2022 The KubeVela 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 executor
    18  
    19  import (
    20  	"testing"
    21  	"time"
    22  
    23  	. "github.com/onsi/ginkgo"
    24  	. "github.com/onsi/gomega"
    25  
    26  	crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
    27  	"k8s.io/apimachinery/pkg/runtime"
    28  	clientgoscheme "k8s.io/client-go/kubernetes/scheme"
    29  	"k8s.io/client-go/rest"
    30  	"k8s.io/utils/pointer"
    31  	"sigs.k8s.io/controller-runtime/pkg/client"
    32  	"sigs.k8s.io/controller-runtime/pkg/envtest"
    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  var scheme = runtime.NewScheme()
    42  
    43  func TestWorkflow(t *testing.T) {
    44  	RegisterFailHandler(Fail)
    45  
    46  	RunSpecs(t, "Test Definition Suite")
    47  }
    48  
    49  var _ = BeforeSuite(func(done Done) {
    50  	By("Bootstrapping test environment")
    51  	testEnv = &envtest.Environment{
    52  		ControlPlaneStartTimeout: time.Minute,
    53  		ControlPlaneStopTimeout:  time.Minute,
    54  		UseExistingCluster:       pointer.BoolPtr(false),
    55  	}
    56  	var err error
    57  	cfg, err = testEnv.Start()
    58  	Expect(err).ToNot(HaveOccurred())
    59  	Expect(cfg).ToNot(BeNil())
    60  	Expect(clientgoscheme.AddToScheme(scheme)).Should(BeNil())
    61  	Expect(crdv1.AddToScheme(scheme)).Should(BeNil())
    62  	// +kubebuilder:scaffold:scheme
    63  	By("Create the k8s client")
    64  	k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
    65  	Expect(err).ToNot(HaveOccurred())
    66  	Expect(k8sClient).ToNot(BeNil())
    67  
    68  	close(done)
    69  }, 60)
    70  
    71  var _ = AfterSuite(func() {
    72  	By("Tearing down the test environment")
    73  	err := testEnv.Stop()
    74  	Expect(err).ToNot(HaveOccurred())
    75  })