github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/peer/config/v2/config_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 v2_test 20 21 import ( 22 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common" 23 v2core "github.com/IBM-Blockchain/fabric-operator/pkg/apis/peer/v2" 24 v2 "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v2" 25 . "github.com/onsi/ginkgo/v2" 26 . "github.com/onsi/gomega" 27 ) 28 29 var _ = Describe("Peer configuration", func() { 30 It("merges current configuration with overrides values", func() { 31 core, err := v2.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 32 Expect(err).NotTo(HaveOccurred()) 33 Expect(core.Peer.ID).To(Equal("jdoe")) 34 35 newConfig := &v2.Core{ 36 Core: v2core.Core{ 37 Peer: v2core.Peer{ 38 BCCSP: &common.BCCSP{ 39 ProviderName: "PKCS11", 40 PKCS11: &common.PKCS11Opts{ 41 Library: "library2", 42 Label: "label2", 43 Pin: "2222", 44 HashFamily: "SHA3", 45 SecLevel: 512, 46 FileKeyStore: &common.FileKeyStoreOpts{ 47 KeyStorePath: "keystore3", 48 }, 49 }, 50 }, 51 }, 52 }, 53 } 54 55 Expect(core.Peer.Keepalive.MinInterval).To(Equal(common.MustParseDuration("60s"))) 56 57 err = core.MergeWith(newConfig, true) 58 Expect(err).NotTo(HaveOccurred()) 59 60 Expect(*core.Peer.BCCSP.PKCS11).To(Equal(common.PKCS11Opts{ 61 Library: "/usr/local/lib/libpkcs11-proxy.so", 62 Label: "label2", 63 Pin: "2222", 64 HashFamily: "SHA3", 65 SecLevel: 512, 66 SoftVerify: true, 67 FileKeyStore: &common.FileKeyStoreOpts{ 68 KeyStorePath: "keystore3", 69 }, 70 })) 71 }) 72 73 Context("chaincode configuration", func() { 74 It("merges v2 current configuration with overrides values", func() { 75 core, err := v2.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 76 Expect(err).NotTo(HaveOccurred()) 77 Expect(core.Peer.ID).To(Equal("jdoe")) 78 79 startupTimeout, err := common.ParseDuration("200s") 80 Expect(err).NotTo(HaveOccurred()) 81 executeTimeout, err := common.ParseDuration("20s") 82 Expect(err).NotTo(HaveOccurred()) 83 84 newConfig := &v2.Core{ 85 Core: v2core.Core{ 86 Chaincode: v2core.Chaincode{ 87 StartupTimeout: startupTimeout, 88 ExecuteTimeout: executeTimeout, 89 ExternalBuilders: []v2core.ExternalBuilder{ 90 v2core.ExternalBuilder{ 91 Path: "/scripts", 92 Name: "go-builder", 93 EnvironmentWhiteList: []string{"ENV1=Value1"}, 94 PropogateEnvironment: []string{"ENV1=Value1"}, 95 }, 96 }, 97 }, 98 }, 99 } 100 101 err = core.MergeWith(newConfig, false) 102 Expect(err).NotTo(HaveOccurred()) 103 Expect(core.Chaincode.StartupTimeout).To(Equal(startupTimeout)) 104 Expect(core.Chaincode.ExecuteTimeout).To(Equal(executeTimeout)) 105 106 Expect(core.Chaincode.ExternalBuilders[0]).To(Equal( 107 v2core.ExternalBuilder{ 108 Path: "/scripts", 109 Name: "go-builder", 110 EnvironmentWhiteList: []string{"ENV1=Value1"}, 111 PropogateEnvironment: []string{"ENV1=Value1"}, 112 }, 113 )) 114 }) 115 }) 116 117 Context("read in core file", func() { 118 It("reads core and converts peer.gossip.bootstrap", func() { 119 core, err := v2.ReadCoreFile("../../../../../testdata/init/peer/core_bootstrap_test.yaml") 120 Expect(err).NotTo(HaveOccurred()) 121 Expect(core.Peer.Gossip.Bootstrap).To(Equal([]string{"127.0.0.1:7051"})) 122 }) 123 124 It("returns error if invalid core (besides peer.gossip.boostrap field)", func() { 125 _, err := v2.ReadCoreFile("../../../../../testdata/init/peer/core_invalid.yaml") 126 Expect(err).NotTo(HaveOccurred()) 127 }) 128 }) 129 })