github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/console/override/service_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  
    26  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    27  	consolev1 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/console/v1"
    28  	"github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources"
    29  	"github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/console/override"
    30  	"github.com/IBM-Blockchain/fabric-operator/pkg/util"
    31  )
    32  
    33  var _ = Describe("Base Console Service Overrides", func() {
    34  	var (
    35  		overrider *override.Override
    36  		instance  *current.IBPConsole
    37  		service   *corev1.Service
    38  	)
    39  
    40  	BeforeEach(func() {
    41  		var err error
    42  
    43  		service, err = util.GetServiceFromFile("../../../../../definitions/console/service.yaml")
    44  		Expect(err).NotTo(HaveOccurred())
    45  
    46  		overrider = &override.Override{}
    47  		instance = &current.IBPConsole{
    48  			Spec: current.IBPConsoleSpec{
    49  				Service: &current.Service{
    50  					Type: corev1.ServiceTypeNodePort,
    51  				},
    52  				NetworkInfo: &current.NetworkInfo{
    53  					ConsolePort: 1234,
    54  				},
    55  			},
    56  		}
    57  	})
    58  
    59  	Context("create", func() {
    60  		It("overrides values based on spec", func() {
    61  			err := overrider.Service(instance, service, resources.Create)
    62  			Expect(err).NotTo(HaveOccurred())
    63  
    64  			By("setting service type", func() {
    65  				Expect(service.Spec.Type).To(Equal(instance.Spec.Service.Type))
    66  			})
    67  
    68  			By("instance spec proxying to ture", func() {
    69  				Expect(*instance.Spec.Proxying).To(Equal(true))
    70  			})
    71  
    72  			By("setting console node port", func() {
    73  				Expect(service.Spec.Ports[0].NodePort).To(Equal(instance.Spec.NetworkInfo.ConsolePort))
    74  			})
    75  		})
    76  
    77  		It("overrides values based on spec with devmode on", func() {
    78  			instance.Spec.FeatureFlags = &consolev1.FeatureFlags{
    79  				DevMode: true,
    80  			}
    81  
    82  			err := overrider.Service(instance, service, resources.Create)
    83  			Expect(err).NotTo(HaveOccurred())
    84  
    85  			By("setting service type", func() {
    86  				Expect(service.Spec.Type).To(Equal(instance.Spec.Service.Type))
    87  			})
    88  
    89  			By("instance spec proxying to ture", func() {
    90  				Expect(*instance.Spec.Proxying).To(Equal(true))
    91  			})
    92  
    93  			By("setting console node port", func() {
    94  				Expect(service.Spec.Ports[0].NodePort).To(Equal(instance.Spec.NetworkInfo.ConsolePort))
    95  			})
    96  		})
    97  
    98  	})
    99  })