github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/command/operator_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 command_test 20 21 import ( 22 "os" 23 24 . "github.com/onsi/ginkgo/v2" 25 . "github.com/onsi/gomega" 26 27 oconfig "github.com/IBM-Blockchain/fabric-operator/operatorconfig" 28 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common" 29 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/deployer" 30 "github.com/IBM-Blockchain/fabric-operator/pkg/command" 31 "github.com/IBM-Blockchain/fabric-operator/pkg/command/mocks" 32 "github.com/IBM-Blockchain/fabric-operator/pkg/offering" 33 ) 34 35 var _ = Describe("Operator command", func() { 36 Context("config initialization", func() { 37 var config *oconfig.Config 38 39 BeforeEach(func() { 40 os.Setenv("CLUSTERTYPE", "K8S") 41 42 config = &oconfig.Config{ 43 Operator: oconfig.Operator{ 44 Versions: &deployer.Versions{ 45 CA: map[string]deployer.VersionCA{}, 46 Peer: map[string]deployer.VersionPeer{}, 47 Orderer: map[string]deployer.VersionOrderer{}, 48 }, 49 }, 50 } 51 }) 52 53 Context("cluster type", func() { 54 It("returns error for invalid cluster type value", func() { 55 os.Setenv("CLUSTERTYPE", "") 56 err := command.InitConfig("", config, &mocks.Reader{}) 57 Expect(err).To(HaveOccurred()) 58 }) 59 60 It("sets value", func() { 61 os.Setenv("CLUSTERTYPE", "K8S") 62 err := command.InitConfig("", config, &mocks.Reader{}) 63 Expect(err).NotTo(HaveOccurred()) 64 Expect(config.Offering).To(Equal(offering.K8S)) 65 }) 66 }) 67 68 Context("secret poll timeout", func() { 69 It("returns default value inf invalid timeout value set", func() { 70 os.Setenv("IBPOPERATOR_ORDERER_TIMEOUTS_SECRETPOLL", "45") 71 err := command.InitConfig("", config, &mocks.Reader{}) 72 Expect(err).To(HaveOccurred()) 73 }) 74 75 It("sets value", func() { 76 os.Setenv("IBPOPERATOR_ORDERER_TIMEOUTS_SECRETPOLL", "45s") 77 err := command.InitConfig("", config, &mocks.Reader{}) 78 Expect(err).NotTo(HaveOccurred()) 79 Expect(config.Operator.Orderer.Timeouts.SecretPoll).To(Equal(common.MustParseDuration("45s"))) 80 }) 81 }) 82 }) 83 })