github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/crd/manager_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 crd_test 20 21 import ( 22 "errors" 23 24 "github.com/IBM-Blockchain/fabric-operator/pkg/crd" 25 "github.com/IBM-Blockchain/fabric-operator/pkg/crd/mocks" 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 ) 29 30 var _ = Describe("manager", func() { 31 var mockClient *mocks.Client 32 33 BeforeEach(func() { 34 mockClient = &mocks.Client{} 35 }) 36 37 Context("NewManager", func() { 38 It("returns an error if it fails to load a file", func() { 39 m, err := crd.NewManager(mockClient, "bad.yaml") 40 Expect(err).To(HaveOccurred()) 41 Expect(err.Error()).To(ContainSubstring("no such file or directory")) 42 Expect(m).To(BeNil()) 43 }) 44 45 It("returns a manager", func() { 46 m, err := crd.NewManager(mockClient, "../../config/crd/bases/ibp.com_ibpcas.yaml") 47 Expect(err).NotTo(HaveOccurred()) 48 Expect(m).NotTo(BeNil()) 49 }) 50 }) 51 52 Context("Create", func() { 53 var ( 54 err error 55 manager *crd.Manager 56 ) 57 58 BeforeEach(func() { 59 manager, err = crd.NewManager(mockClient, "../../config/crd/bases/ibp.com_ibpcas.yaml") 60 Expect(err).NotTo(HaveOccurred()) 61 }) 62 63 It("returns an error if it fails to create CRD", func() { 64 mockClient.CreateCRDReturns(nil, errors.New("failed to create crd")) 65 err = manager.Create() 66 Expect(err).To(HaveOccurred()) 67 Expect(err.Error()).To(ContainSubstring("failed to create crd")) 68 }) 69 70 It("returns no error on successful creation", func() { 71 err = manager.Create() 72 Expect(err).NotTo(HaveOccurred()) 73 }) 74 }) 75 })