github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/controllers/apps/backuppolicytemplate_controller_test.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 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 apps 18 19 import ( 20 . "github.com/onsi/ginkgo/v2" 21 . "github.com/onsi/gomega" 22 23 "sigs.k8s.io/controller-runtime/pkg/client" 24 25 "github.com/1aal/kubeblocks/apis/apps/v1alpha1" 26 "github.com/1aal/kubeblocks/pkg/constant" 27 intctrlutil "github.com/1aal/kubeblocks/pkg/generics" 28 testapps "github.com/1aal/kubeblocks/pkg/testutil/apps" 29 ) 30 31 var _ = Describe("", func() { 32 var ( 33 BackupPolicyTemplateName = "test-bpt" 34 ClusterDefName = "test-cd" 35 BackupPolicyName = "test-bp" 36 BackupMethod = "test-bm" 37 ActionSetName = "test-as" 38 VsBackupMethodName = "test-vs-bm" 39 VsActionSetName = "test-vs-as" 40 ) 41 42 cleanEnv := func() { 43 // must wait till resources deleted and no longer existed before the testcases start, 44 // otherwise if later it needs to create some new resource objects with the same name, 45 // in race conditions, it will find the existence of old objects, resulting failure to 46 // create the new objects. 47 By("clean resources") 48 49 ml := client.HasLabels{testCtx.TestObjLabelKey} 50 testapps.ClearResourcesWithRemoveFinalizerOption(&testCtx, intctrlutil.BackupPolicyTemplateSignature, true, ml) 51 } 52 53 BeforeEach(func() { 54 cleanEnv() 55 }) 56 57 AfterEach(func() { 58 cleanEnv() 59 }) 60 61 Context("create a backuppolicytemplate", func() { 62 It("should be available", func() { 63 bpt := testapps.NewBackupPolicyTemplateFactory(BackupPolicyTemplateName). 64 SetClusterDefRef(ClusterDefName). 65 AddBackupPolicy(BackupPolicyName). 66 AddBackupMethod(BackupMethod, false, ActionSetName). 67 SetBackupMethodVolumeMounts("data", "/data"). 68 AddBackupMethod(VsBackupMethodName, true, VsActionSetName). 69 SetBackupMethodVolumeMounts("data", "/data"). 70 AddSchedule(BackupMethod, "0 0 * * *", true). 71 AddSchedule(VsBackupMethodName, "0 0 * * *", true). 72 Create(&testCtx).GetObject() 73 key := client.ObjectKeyFromObject(bpt) 74 Eventually(testapps.CheckObj(&testCtx, key, func(g Gomega, pobj *v1alpha1.BackupPolicyTemplate) { 75 g.Expect(pobj.GetLabels()[constant.ClusterDefLabelKey]).To(Equal(bpt.Spec.ClusterDefRef)) 76 })).Should(Succeed()) 77 }) 78 }) 79 80 })