github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/common/enroller/factory_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 enroller_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/pkg/initializer/common/enroller"
    27  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/enroller/mocks"
    28  
    29  	"k8s.io/apimachinery/pkg/runtime"
    30  )
    31  
    32  var _ = Describe("Enroller factory", func() {
    33  	var instance *mocks.CryptoInstance
    34  
    35  	BeforeEach(func() {
    36  		instance = &mocks.CryptoInstance{}
    37  	})
    38  
    39  	Context("software enroller", func() {
    40  		It("returns software type enroller", func() {
    41  			e, err := enroller.Factory(&current.Enrollment{}, &mocks.Client{}, instance, "/tmp", &runtime.Scheme{}, []byte("cert"), enroller.HSMEnrollJobTimeouts{})
    42  			Expect(err).NotTo(HaveOccurred())
    43  
    44  			_, sw := e.Enroller.(*enroller.SWEnroller)
    45  			Expect(sw).To(Equal(true))
    46  		})
    47  	})
    48  
    49  	Context("HSM", func() {
    50  		BeforeEach(func() {
    51  			instance.IsHSMEnabledReturns(true)
    52  		})
    53  
    54  		Context("sidecar enroller", func() {
    55  			It("returns sidecar type enroller", func() {
    56  				e, err := enroller.Factory(&current.Enrollment{}, &mocks.Client{}, instance, "/tmp", &runtime.Scheme{}, []byte("cert"), enroller.HSMEnrollJobTimeouts{})
    57  				Expect(err).NotTo(HaveOccurred())
    58  
    59  				_, hsm := e.Enroller.(*enroller.HSMEnroller)
    60  				Expect(hsm).To(Equal(true))
    61  			})
    62  		})
    63  
    64  		Context("proxy enroller", func() {
    65  			BeforeEach(func() {
    66  				instance.UsingHSMProxyReturns(true)
    67  			})
    68  
    69  			It("returns sidecar type enroller", func() {
    70  				e, err := enroller.Factory(&current.Enrollment{}, &mocks.Client{}, instance, "/tmp", &runtime.Scheme{}, []byte("cert"), enroller.HSMEnrollJobTimeouts{})
    71  				Expect(err).NotTo(HaveOccurred())
    72  
    73  				_, hsm := e.Enroller.(*enroller.HSMProxyEnroller)
    74  				Expect(hsm).To(Equal(true))
    75  			})
    76  		})
    77  	})
    78  })