github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/peer/peer_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 initializer_test
    20  
    21  import (
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  	"github.com/pkg/errors"
    25  
    26  	commonapi "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common"
    27  	v1 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/peer/v1"
    28  	commonconfig "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config"
    29  	configmocks "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config/mocks"
    30  	initializer "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer"
    31  	config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v1"
    32  )
    33  
    34  var _ = Describe("peer", func() {
    35  	var (
    36  		peer *initializer.Peer
    37  
    38  		mockCrypto *configmocks.Crypto
    39  	)
    40  
    41  	BeforeEach(func() {
    42  		mockCrypto = &configmocks.Crypto{}
    43  
    44  		peer = &initializer.Peer{
    45  			Config: &config.Core{},
    46  			Cryptos: &commonconfig.Cryptos{
    47  				Enrollment: mockCrypto,
    48  			},
    49  		}
    50  	})
    51  
    52  	Context("config override", func() {
    53  		When("using hsm proxy", func() {
    54  			BeforeEach(func() {
    55  				peer.UsingHSMProxy = true
    56  			})
    57  
    58  			It("overrides peer's config", func() {
    59  				core := &config.Core{
    60  					Core: v1.Core{
    61  						Peer: v1.Peer{
    62  							BCCSP: &commonapi.BCCSP{
    63  								ProviderName: "PKCS11",
    64  								PKCS11:       &commonapi.PKCS11Opts{},
    65  							},
    66  						},
    67  					},
    68  				}
    69  
    70  				err := peer.OverrideConfig(core)
    71  				Expect(err).NotTo(HaveOccurred())
    72  
    73  				Expect(core.Peer.BCCSP.PKCS11.Library).To(Equal("/usr/local/lib/libpkcs11-proxy.so"))
    74  			})
    75  		})
    76  	})
    77  
    78  	Context("generate crypto", func() {
    79  		It("returns error if unable to get crypto", func() {
    80  			mockCrypto.GetCryptoReturns(nil, errors.New("get crypto error"))
    81  			_, err := peer.GenerateCrypto()
    82  			Expect(err).To(HaveOccurred())
    83  		})
    84  
    85  		It("gets crypto", func() {
    86  			resp, err := peer.GenerateCrypto()
    87  			Expect(err).NotTo(HaveOccurred())
    88  			Expect(resp).NotTo(BeNil())
    89  		})
    90  	})
    91  })