github.com/IBM-Blockchain/fabric-operator@v1.0.4/integration/cclauncher/cclauncher_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 cclauncher_test 20 21 import ( 22 "context" 23 "fmt" 24 25 . "github.com/onsi/ginkgo/v2" 26 . "github.com/onsi/gomega" 27 28 v2 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/peer/v2" 29 30 corev1 "k8s.io/api/core/v1" 31 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 32 33 "sigs.k8s.io/yaml" 34 ) 35 36 var _ = Describe("chaincode launcher", func() { 37 AfterEach(func() { 38 // Set flag if a test falls 39 if CurrentGinkgoTestDescription().Failed { 40 testFailed = true 41 } 42 }) 43 44 Context("V2 Peer", func() { 45 It("creates peer resources", func() { 46 By("creating deployment that contains four containers", func() { 47 dep, err := kclient.AppsV1().Deployments(namespace).Get(context.TODO(), org1peer.Name, metav1.GetOptions{}) 48 Expect(err).NotTo(HaveOccurred()) 49 50 Expect(dep.Spec.Template.Spec.Containers).To(HaveLen(4)) 51 }) 52 53 By("creating config map with external builders", func() { 54 cm, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), fmt.Sprintf("%s-config", org1peer.Name), metav1.GetOptions{}) 55 Expect(err).NotTo(HaveOccurred()) 56 57 v2Core := &v2.Core{} 58 coreBytes := cm.BinaryData["core.yaml"] 59 err = yaml.Unmarshal(coreBytes, v2Core) 60 Expect(err).NotTo(HaveOccurred()) 61 62 extBuilder := v2.ExternalBuilder{ 63 Path: "/usr/local", 64 Name: "ibp-builder", 65 EnvironmentWhiteList: []string{ 66 "IBP_BUILDER_ENDPOINT", 67 "IBP_BUILDER_SHARED_DIR", 68 }, 69 PropogateEnvironment: []string{ 70 "IBP_BUILDER_ENDPOINT", 71 "IBP_BUILDER_SHARED_DIR", 72 "PEER_NAME", 73 }, 74 } 75 Expect(v2Core.Chaincode.ExternalBuilders).To(ContainElement(extBuilder)) 76 }) 77 78 By("setting builders environment variables", func() { 79 dep, err := kclient.AppsV1().Deployments(namespace).Get(context.TODO(), org1peer.Name, metav1.GetOptions{}) 80 Expect(err).NotTo(HaveOccurred()) 81 82 peerContainer := dep.Spec.Template.Spec.Containers[0] 83 84 dirEnvVar := corev1.EnvVar{ 85 Name: "IBP_BUILDER_SHARED_DIR", 86 Value: "/cclauncher", 87 } 88 Expect(peerContainer.Env).To(ContainElement(dirEnvVar)) 89 90 endpointEnvVar := corev1.EnvVar{ 91 Name: "IBP_BUILDER_ENDPOINT", 92 Value: "127.0.0.1:11111", 93 } 94 Expect(peerContainer.Env).To(ContainElement(endpointEnvVar)) 95 }) 96 }) 97 }) 98 })