github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/console/override/consolecm_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 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 corev1 "k8s.io/api/core/v1" 25 "sigs.k8s.io/yaml" 26 27 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 28 consolev1 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/console/v1" 29 "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" 30 "github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/console/override" 31 "github.com/IBM-Blockchain/fabric-operator/pkg/util" 32 ) 33 34 var _ = Describe("Base Console 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 Email: "test@ibm.com", 47 AuthScheme: "scheme1", 48 AllowDefaultPassword: true, 49 ConfigtxlatorURL: "configtx.ibm.com", 50 DeployerURL: "deployer.ibm.com", 51 DeployerTimeout: 5, 52 Components: "component1", 53 Sessions: "session1", 54 System: "system1", 55 SystemChannel: "channel1", 56 FeatureFlags: &consolev1.FeatureFlags{ 57 CreateChannelEnabled: true, 58 }, 59 ClusterData: &consolev1.IBPConsoleClusterData{ 60 Zones: []string{"zone1"}, 61 Type: "type1", 62 }, 63 }, 64 } 65 cm, err = util.GetConfigMapFromFile("../../../../../definitions/console/console-configmap.yaml") 66 Expect(err).NotTo(HaveOccurred()) 67 }) 68 69 Context("create", func() { 70 It("returns an error if base create function called", func() { 71 err := overrider.ConsoleCM(instance, cm, resources.Create, nil) 72 Expect(err).To(HaveOccurred()) 73 Expect(err.Error()).To(Equal("no create console cm defined, this needs to implemented")) 74 }) 75 }) 76 77 Context("update", func() { 78 It("overrides values based on spec", func() { 79 err := overrider.ConsoleCM(instance, cm, resources.Update, nil) 80 Expect(err).NotTo(HaveOccurred()) 81 82 config := &consolev1.ConsoleSettingsConfig{} 83 err = yaml.Unmarshal([]byte(cm.Data["settings.yaml"]), config) 84 Expect(err).NotTo(HaveOccurred()) 85 86 By("setting email", func() { 87 Expect(config.Email).To(Equal(instance.Spec.Email)) 88 }) 89 90 By("setting auth scheme", func() { 91 Expect(config.AuthScheme).To(Equal(instance.Spec.AuthScheme)) 92 }) 93 94 By("setting allow_default_password", func() { 95 Expect(config.AllowDefaultPassword).To(Equal(instance.Spec.AllowDefaultPassword)) 96 }) 97 98 By("setting configtxlator URL", func() { 99 Expect(config.Configtxlator).To(Equal(instance.Spec.ConfigtxlatorURL)) 100 }) 101 102 By("setting Deployer URL", func() { 103 Expect(config.DeployerURL).To(Equal(instance.Spec.DeployerURL)) 104 }) 105 106 By("setting Deployer timeout", func() { 107 Expect(config.DeployerTimeout).To(Equal(instance.Spec.DeployerTimeout)) 108 }) 109 110 By("setting components", func() { 111 Expect(config.DBCustomNames.Components).To(Equal(instance.Spec.Components)) 112 }) 113 114 By("setting sessions", func() { 115 Expect(config.DBCustomNames.Sessions).To(Equal(instance.Spec.Sessions)) 116 }) 117 118 By("setting system", func() { 119 Expect(config.DBCustomNames.System).To(Equal(instance.Spec.System)) 120 }) 121 122 By("setting system channel", func() { 123 Expect(config.SystemChannelID).To(Equal(instance.Spec.SystemChannel)) 124 }) 125 126 By("setting Proxy TLS Reqs", func() { 127 Expect(config.ProxyTLSReqs).To(Equal("always")) 128 }) 129 130 By("settings feature flags", func() { 131 Expect(config.Featureflags).To(Equal(instance.Spec.FeatureFlags)) 132 }) 133 134 By("settings cluster data", func() { 135 Expect(config.ClusterData).To(Equal(instance.Spec.ClusterData)) 136 }) 137 138 By("setting trust proxy", func() { 139 Expect(config.TrustProxy).To(Equal("loopback, linklocal, uniquelocal")) 140 }) 141 }) 142 143 It("overrides values based on defaults", func() { 144 instance = ¤t.IBPConsole{} 145 err := overrider.ConsoleCM(instance, cm, resources.Update, nil) 146 Expect(err).NotTo(HaveOccurred()) 147 148 config := &consolev1.ConsoleSettingsConfig{} 149 err = yaml.Unmarshal([]byte(cm.Data["settings.yaml"]), config) 150 Expect(err).NotTo(HaveOccurred()) 151 152 By("settings feature flags", func() { 153 ff := &consolev1.FeatureFlags{ 154 ReadOnlyEnabled: new(bool), 155 ImportOnlyEnabled: new(bool), 156 CreateChannelEnabled: true, 157 RemotePeerConfigEnabled: true, 158 TemplatesEnabled: false, 159 CapabilitiesEnabled: true, 160 HighAvailability: true, 161 EnableNodeOU: true, 162 HSMEnabled: true, 163 ScaleRaftNodesEnabled: true, 164 Lifecycle20Enabled: true, 165 Patch14to20Enabled: true, 166 MustgatherEnabled: true, 167 InfraImportOptions: &consolev1.InfraImportOptions{ 168 SupportedCAs: []string{override.OPENSHIFT, override.K8S}, 169 SupportedOrderers: []string{override.OPENSHIFT, override.K8S}, 170 SupportedPeers: []string{override.OPENSHIFT, override.K8S}, 171 }, 172 } 173 174 Expect(config.Featureflags).To(Equal(ff)) 175 }) 176 177 By("settings cluster data", func() { 178 cd := &consolev1.IBPConsoleClusterData{ 179 Type: "paid", 180 } 181 Expect(config.ClusterData).To(Equal(cd)) 182 }) 183 }) 184 }) 185 })