github.com/oam-dev/kubevela@v1.9.11/cmd/core/app/hooks/pre_start_hook_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 hooks_test 18 19 import ( 20 "context" 21 "testing" 22 23 "github.com/kubevela/pkg/util/k8s" 24 "github.com/kubevela/pkg/util/singleton" 25 "github.com/kubevela/pkg/util/test/bootstrap" 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 utilfeature "k8s.io/apiserver/pkg/util/feature" 29 featuregatetesting "k8s.io/component-base/featuregate/testing" 30 31 "github.com/oam-dev/kubevela/apis/types" 32 "github.com/oam-dev/kubevela/cmd/core/app/hooks" 33 "github.com/oam-dev/kubevela/pkg/features" 34 ) 35 36 var _ = bootstrap.InitKubeBuilderForTest(bootstrap.WithCRDPath("./testdata")) 37 38 func TestPreStartHook(t *testing.T) { 39 RegisterFailHandler(Fail) 40 RunSpecs(t, "Run pre-start hook test") 41 } 42 43 var _ = Describe("Test pre-start hooks", func() { 44 It("Test SystemCRDValidationHook", func() { 45 defer featuregatetesting.SetFeatureGateDuringTest(&testing.T{}, utilfeature.DefaultFeatureGate, features.ZstdApplicationRevision, true)() 46 ctx := context.Background() 47 Expect(k8s.EnsureNamespace(ctx, singleton.KubeClient.Get(), types.DefaultKubeVelaNS)).Should(Succeed()) 48 err := hooks.NewSystemCRDValidationHook().Run(ctx) 49 Expect(err).ShouldNot(Succeed()) 50 Expect(err.Error()).Should(ContainSubstring("the ApplicationRevision CRD is not updated")) 51 }) 52 })