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