github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/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  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  
    25  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    26  	"github.com/IBM-Blockchain/fabric-operator/controllers/mocks"
    27  	"github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/peer/override"
    28  )
    29  
    30  var _ = Describe("Base Peer Overrides", func() {
    31  	var (
    32  		overrider *override.Override
    33  		instance  *current.IBPPeer
    34  	)
    35  
    36  	BeforeEach(func() {
    37  		overrider = &override.Override{
    38  			Client: &mocks.Client{},
    39  		}
    40  		instance = &current.IBPPeer{}
    41  	})
    42  
    43  	Context("Affnity", func() {
    44  		BeforeEach(func() {
    45  			instance = &current.IBPPeer{
    46  				Spec: current.IBPPeerSpec{
    47  					MSPID:  "peer-msp-id",
    48  					Arch:   []string{"test-arch"},
    49  					Zone:   "dal",
    50  					Region: "us-south",
    51  				},
    52  			}
    53  		})
    54  
    55  		It("returns an proper affinity when arch is passed", func() {
    56  			a := overrider.GetAffinity(instance)
    57  			Expect(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Values).To(Equal([]string{"test-arch"}))
    58  			Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Key).To(Equal("orgname"))
    59  			Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Values).To(Equal([]string{"peer-msp-id"}))
    60  			Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Weight).To(Equal(int32(100)))
    61  		})
    62  
    63  		It("returns an proper affinity when no arch is passed", func() {
    64  			instance.Spec.Arch = []string{}
    65  			a := overrider.GetAffinity(instance)
    66  			Expect(a.NodeAffinity).NotTo(BeNil())
    67  			Expect(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[0].Values).To(Equal([]string{"dal"}))
    68  			Expect(a.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions[1].Values).To(Equal([]string{"us-south"}))
    69  			Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Key).To(Equal("orgname"))
    70  			Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm.LabelSelector.MatchExpressions[0].Values).To(Equal([]string{"peer-msp-id"}))
    71  			Expect(a.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Weight).To(Equal(int32(100)))
    72  		})
    73  	})
    74  })