github.com/oam-dev/kubevela@v1.9.11/pkg/utils/helm/helm_suite_test.go (about) 1 /* 2 Copyright 2021 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 helm 18 19 import ( 20 "math/rand" 21 "testing" 22 "time" 23 24 "github.com/oam-dev/kubevela/pkg/utils/common" 25 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 "k8s.io/client-go/rest" 29 "k8s.io/utils/pointer" 30 "sigs.k8s.io/controller-runtime/pkg/client" 31 "sigs.k8s.io/controller-runtime/pkg/envtest" 32 ) 33 34 var cfg *rest.Config 35 var k8sClient client.Client 36 var testEnv *envtest.Environment 37 38 var _ = BeforeSuite(func() { 39 rand.Seed(time.Now().UnixNano()) 40 By("bootstrapping test environment") 41 42 testEnv = &envtest.Environment{ 43 ControlPlaneStartTimeout: time.Minute * 3, 44 ControlPlaneStopTimeout: time.Minute, 45 UseExistingCluster: pointer.Bool(false), 46 } 47 48 By("start kube test env") 49 var err error 50 cfg, err = testEnv.Start() 51 Expect(err).ShouldNot(HaveOccurred()) 52 Expect(cfg).ToNot(BeNil()) 53 54 k8sClient, err = client.New(cfg, client.Options{Scheme: common.Scheme}) 55 Expect(err).Should(BeNil()) 56 Expect(k8sClient).ToNot(BeNil()) 57 }) 58 59 var _ = AfterSuite(func() { 60 if testEnv != nil { 61 err := testEnv.Stop() 62 Expect(err).Should(BeNil()) 63 } 64 }) 65 66 func TestHelm(t *testing.T) { 67 RegisterFailHandler(Fail) 68 RunSpecs(t, "Helm Suite") 69 }