github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/openshift/peer/override/override_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  	"k8s.io/apimachinery/pkg/util/intstr"
    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/openshift/peer/override"
    31  	routev1 "github.com/openshift/api/route/v1"
    32  )
    33  
    34  var _ = Describe("Openshift Peer Overrides", func() {
    35  	var (
    36  		route     *routev1.Route
    37  		overrider *override.Override
    38  		instance  *current.IBPPeer
    39  	)
    40  
    41  	BeforeEach(func() {
    42  		route = &routev1.Route{}
    43  		overrider = &override.Override{}
    44  
    45  		instance = &current.IBPPeer{
    46  			Spec: current.IBPPeerSpec{
    47  				Domain: "test-domain",
    48  			},
    49  		}
    50  		instance.Name = "route1"
    51  		instance.Namespace = "testNS"
    52  	})
    53  
    54  	Context("Peer Route", func() {
    55  		When("creating a new Peer Route", func() {
    56  			It("appropriately overrides the respective values", func() {
    57  				err := overrider.PeerRoute(instance, route, resources.Create)
    58  				Expect(err).NotTo(HaveOccurred())
    59  
    60  				Expect(route.Name).To(Equal(fmt.Sprintf("%s-peer", instance.Name)))
    61  				Expect(route.Spec.Host).To(Equal("testNS-route1-peer.test-domain"))
    62  				Expect(route.Spec.To.Kind).To(Equal("Service"))
    63  				Expect(route.Spec.To.Name).To(Equal(instance.Name))
    64  				Expect(*route.Spec.To.Weight).To(Equal(int32(100)))
    65  				Expect(route.Spec.Port.TargetPort).To(Equal(intstr.FromString("peer-api")))
    66  				Expect(route.Spec.TLS.Termination).To(Equal(routev1.TLSTerminationPassthrough))
    67  			})
    68  		})
    69  	})
    70  
    71  	Context("Operation Route", func() {
    72  		When("creating a new Operation Route", func() {
    73  			It("appropriately overrides the respective values", func() {
    74  				err := overrider.OperationsRoute(instance, route, resources.Create)
    75  				Expect(err).NotTo(HaveOccurred())
    76  
    77  				Expect(route.Name).To(Equal(fmt.Sprintf("%s-operations", instance.Name)))
    78  				Expect(route.Spec.Host).To(Equal("testNS-route1-operations.test-domain"))
    79  				Expect(route.Spec.To.Kind).To(Equal("Service"))
    80  				Expect(route.Spec.To.Name).To(Equal(instance.Name))
    81  				Expect(*route.Spec.To.Weight).To(Equal(int32(100)))
    82  				Expect(route.Spec.Port.TargetPort).To(Equal(intstr.FromString("operations")))
    83  				Expect(route.Spec.TLS.Termination).To(Equal(routev1.TLSTerminationPassthrough))
    84  			})
    85  		})
    86  	})
    87  
    88  	Context("GPRC Route", func() {
    89  		When("creating a new GRPC Route", func() {
    90  			It("appropriately overrides the respective values", func() {
    91  				err := overrider.PeerGRPCRoute(instance, route, resources.Create)
    92  				Expect(err).NotTo(HaveOccurred())
    93  
    94  				Expect(route.Name).To(Equal(fmt.Sprintf("%s-grpcweb", instance.Name)))
    95  				Expect(route.Spec.Host).To(Equal("testNS-route1-grpcweb.test-domain"))
    96  				Expect(route.Spec.To.Kind).To(Equal("Service"))
    97  				Expect(route.Spec.To.Name).To(Equal(instance.Name))
    98  				Expect(*route.Spec.To.Weight).To(Equal(int32(100)))
    99  				Expect(route.Spec.Port.TargetPort).To(Equal(intstr.FromString("grpcweb")))
   100  				Expect(route.Spec.TLS.Termination).To(Equal(routev1.TLSTerminationPassthrough))
   101  			})
   102  		})
   103  	})
   104  })