github.com/oam-dev/kubevela@v1.9.11/pkg/velaql/providers/query/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 query 18 19 import ( 20 "context" 21 "testing" 22 "time" 23 24 . "github.com/onsi/ginkgo/v2" 25 . "github.com/onsi/gomega" 26 batchv1 "k8s.io/api/batch/v1" 27 "k8s.io/client-go/rest" 28 "k8s.io/utils/pointer" 29 "sigs.k8s.io/controller-runtime/pkg/client" 30 "sigs.k8s.io/controller-runtime/pkg/envtest" 31 32 "github.com/oam-dev/kubevela/pkg/utils/common" 33 ) 34 35 var cfg *rest.Config 36 var k8sClient client.Client 37 var testEnv *envtest.Environment 38 var ctx context.Context 39 40 var _ = BeforeSuite(func() { 41 By("bootstrapping test environment") 42 43 testEnv = &envtest.Environment{ 44 ControlPlaneStartTimeout: time.Minute * 3, 45 ControlPlaneStopTimeout: time.Minute, 46 UseExistingCluster: pointer.Bool(false), 47 CRDDirectoryPaths: []string{ 48 "./testdata/gateway/crds", 49 "../../../../charts/vela-core/crds", 50 "./testdata/machinelearning.seldon.io_seldondeployments.yaml", 51 "./testdata/helm-release-crd.yaml", 52 }, 53 } 54 55 By("start kube test env") 56 var err error 57 cfg, err = testEnv.Start() 58 Expect(err).ShouldNot(HaveOccurred()) 59 Expect(cfg).ToNot(BeNil()) 60 61 By("new kube client") 62 cfg.Timeout = time.Minute * 2 63 64 scheme := common.Scheme 65 batchv1.AddToScheme(scheme) 66 67 k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) 68 69 Expect(err).Should(BeNil()) 70 Expect(k8sClient).ToNot(BeNil()) 71 72 ctx = context.Background() 73 Expect(err).To(BeNil()) 74 }) 75 76 var _ = AfterSuite(func() { 77 By("tearing down the test environment") 78 err := testEnv.Stop() 79 Expect(err).ToNot(HaveOccurred()) 80 }) 81 82 func TestQueryProvider(t *testing.T) { 83 RegisterFailHandler(Fail) 84 RunSpecs(t, "VelaQL Suite") 85 }