github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/k8s/console/override/envcm_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 "fmt" 23 24 . "github.com/onsi/ginkgo/v2" 25 . "github.com/onsi/gomega" 26 corev1 "k8s.io/api/core/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/console/override" 31 "github.com/IBM-Blockchain/fabric-operator/pkg/util" 32 ) 33 34 var _ = Describe("K8s Console Env Config Map Overrides", func() { 35 var ( 36 overrider *override.Override 37 instance *current.IBPConsole 38 cm *corev1.ConfigMap 39 ) 40 41 BeforeEach(func() { 42 var err error 43 overrider = &override.Override{} 44 instance = ¤t.IBPConsole{ 45 Spec: current.IBPConsoleSpec{ 46 ConnectionString: "connection_string", 47 TLSSecretName: "tls_secret_name", 48 System: "system1", 49 NetworkInfo: ¤t.NetworkInfo{ 50 Domain: "test.domain", 51 ConsolePort: 31010, 52 ProxyPort: 31011, 53 }, 54 }, 55 } 56 cm, err = util.GetConfigMapFromFile("../../../../../definitions/console/configmap.yaml") 57 Expect(err).NotTo(HaveOccurred()) 58 }) 59 60 Context("create", func() { 61 It("appropriately overrides the respective values for env config map", func() { 62 err := overrider.CM(instance, cm, resources.Create, nil) 63 Expect(err).NotTo(HaveOccurred()) 64 65 By("setting HOST_URL", func() { 66 consolehost := instance.Namespace + "-" + instance.Name + "-console" + "." + instance.Spec.NetworkInfo.Domain 67 Expect(cm.Data["HOST_URL"]).To(Equal(fmt.Sprintf("https://%s:443", consolehost))) 68 }) 69 70 By("setting DB_CONNECTION_STRING", func() { 71 Expect(cm.Data["DB_CONNECTION_STRING"]).To(Equal(instance.Spec.ConnectionString)) 72 }) 73 74 By("setting DB_SYSTEM", func() { 75 Expect(cm.Data["DB_SYSTEM"]).To(Equal(instance.Spec.System)) 76 }) 77 78 By("setting KEY_FILE_PATH", func() { 79 Expect(cm.Data["KEY_FILE_PATH"]).To(Equal("/certs/tls/tls.key")) 80 }) 81 82 By("setting PEM_FILE_PATH", func() { 83 Expect(cm.Data["PEM_FILE_PATH"]).To(Equal("/certs/tls/tls.crt")) 84 }) 85 }) 86 }) 87 })