github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/base/ca/override/serviceaccount_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 Account Overrides", func() {
    35  	var (
    36  		overrider *override.Override
    37  		instance  *current.IBPCA
    38  		sa        *corev1.ServiceAccount
    39  	)
    40  
    41  	BeforeEach(func() {
    42  		var err error
    43  
    44  		overrider = &override.Override{}
    45  		sa, err = util.GetServiceAccountFromFile("../../../../../definitions/ca/serviceaccount.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  				ImagePullSecrets: []string{"pullsecret1"},
    55  			},
    56  		}
    57  	})
    58  
    59  	Context("creating a new service account", func() {
    60  		It("overrides values in service account, based on CA's instance spec", func() {
    61  			err := overrider.ServiceAccount(instance, sa, resources.Create)
    62  			Expect(err).NotTo(HaveOccurred())
    63  
    64  			By("setting the image pull secret", func() {
    65  				Expect(sa.ImagePullSecrets[1].Name).To(Equal(instance.Spec.ImagePullSecrets[0]))
    66  			})
    67  		})
    68  	})
    69  })