github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/ca/override/pvc_test.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package override_test 20 21 import ( 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 25 corev1 "k8s.io/api/core/v1" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 28 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 29 "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" 30 "github.com/IBM-Blockchain/fabric-operator/pkg/offering/k8s/ca/override" 31 "github.com/IBM-Blockchain/fabric-operator/pkg/util" 32 ) 33 34 var _ = Describe("PVC Overrides", func() { 35 var ( 36 overrider *override.Override 37 instance *current.IBPCA 38 pvc *corev1.PersistentVolumeClaim 39 ) 40 41 BeforeEach(func() { 42 var err error 43 44 overrider = &override.Override{} 45 pvc, err = util.GetPVCFromFile("../../../../../definitions/ca/pvc.yaml") 46 Expect(err).NotTo(HaveOccurred()) 47 48 instance = ¤t.IBPCA{ 49 ObjectMeta: metav1.ObjectMeta{ 50 Name: "override1", 51 Namespace: "namespace1", 52 }, 53 Spec: current.IBPCASpec{ 54 Storage: ¤t.CAStorages{ 55 CA: ¤t.StorageSpec{ 56 Size: "200M", 57 Class: "not-manual", 58 }, 59 }, 60 Region: "fakeregion", 61 Zone: "fakezone", 62 }, 63 } 64 }) 65 66 Context("creating a new pvc", func() { 67 It("returns an error if improperly formatted value for size is used", func() { 68 instance.Spec.Storage.CA.Size = "123b" 69 err := overrider.PVC(instance, pvc, resources.Create) 70 Expect(err).To(HaveOccurred()) 71 Expect(err.Error()).To(ContainSubstring("quantities must match the regular expression")) 72 }) 73 74 It("overrides values in pvc, based on CA's instance spec", func() { 75 Expect(pvc.Spec.StorageClassName).To(BeNil()) 76 err := overrider.PVC(instance, pvc, resources.Create) 77 Expect(err).NotTo(HaveOccurred()) 78 79 By("setting the labels for zone and region", func() { 80 Expect(pvc.ObjectMeta.Labels["region"]).To(Equal("fakeregion")) 81 Expect(pvc.ObjectMeta.Labels["zone"]).To(Equal("fakezone")) 82 }) 83 84 By("setting the storage class name and size", func() { 85 Expect(*pvc.Spec.StorageClassName).To(Equal("not-manual")) 86 q := pvc.Spec.Resources.Requests[corev1.ResourceStorage] 87 Expect(q.String()).To(Equal("200M")) 88 }) 89 90 }) 91 }) 92 })