github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/ca/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  
    25  	corev1 "k8s.io/api/core/v1"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    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/k8s/ca/override"
    31  	"github.com/IBM-Blockchain/fabric-operator/pkg/util"
    32  )
    33  
    34  var _ = Describe("Service Overrides", func() {
    35  	var (
    36  		overrider *override.Override
    37  		instance  *current.IBPCA
    38  		service   *corev1.Service
    39  	)
    40  
    41  	BeforeEach(func() {
    42  		var err error
    43  
    44  		overrider = &override.Override{}
    45  		service, err = util.GetServiceFromFile("../../../../../definitions/ca/service.yaml")
    46  		Expect(err).NotTo(HaveOccurred())
    47  
    48  		instance = &current.IBPCA{
    49  			ObjectMeta: metav1.ObjectMeta{
    50  				Name:      "override1",
    51  				Namespace: "namespace1",
    52  			},
    53  			Spec: current.IBPCASpec{
    54  				Service: &current.Service{
    55  					Type: corev1.ServiceTypeClusterIP,
    56  				},
    57  			},
    58  		}
    59  	})
    60  
    61  	Context("creating a new service", func() {
    62  		It("overrides values in service, based on CA's instance spec", func() {
    63  			err := overrider.Service(instance, service, resources.Create)
    64  			Expect(err).NotTo(HaveOccurred())
    65  
    66  			By("setting the service type", func() {
    67  				Expect(service.Spec.Type).To(Equal(corev1.ServiceTypeClusterIP))
    68  			})
    69  		})
    70  	})
    71  })