github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/common/config/hsmconfig_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 config_test
    20  
    21  import (
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  
    25  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config"
    26  	corev1 "k8s.io/api/core/v1"
    27  )
    28  
    29  var _ = Describe("HSM Config", func() {
    30  	var hsmConfig *config.HSMConfig
    31  
    32  	BeforeEach(func() {
    33  		hsmConfig = &config.HSMConfig{
    34  			Type:    "hsm",
    35  			Version: "v1",
    36  			MountPaths: []config.MountPath{
    37  				config.MountPath{
    38  					Name:      "hsmcrypto",
    39  					Secret:    "hsmcrypto",
    40  					MountPath: "/hsm",
    41  					Paths: []config.Path{
    42  						{
    43  							Key:  "cert.pem",
    44  							Path: "cert.pem",
    45  						},
    46  						{
    47  							Key:  "key.pem",
    48  							Path: "key.pem",
    49  						},
    50  					},
    51  				},
    52  				config.MountPath{
    53  					Name:      "hsmconfig",
    54  					Secret:    "hsmcrypto",
    55  					MountPath: "/etc/Chrystoki.conf",
    56  					SubPath:   "Chrystoki.conf",
    57  				},
    58  			},
    59  			Envs: []corev1.EnvVar{
    60  				{
    61  					Name:  "env1",
    62  					Value: "env1value",
    63  				},
    64  			},
    65  		}
    66  	})
    67  
    68  	Context("volume mounts", func() {
    69  		It("builds volume mounts from config", func() {
    70  			vms := hsmConfig.GetVolumeMounts()
    71  			Expect(vms).To(ContainElements(
    72  				corev1.VolumeMount{
    73  					Name:      "hsmcrypto",
    74  					MountPath: "/hsm",
    75  				},
    76  				corev1.VolumeMount{
    77  					Name:      "hsmconfig",
    78  					MountPath: "/etc/Chrystoki.conf",
    79  					SubPath:   "Chrystoki.conf",
    80  				},
    81  			))
    82  		})
    83  	})
    84  
    85  	Context("volumes", func() {
    86  		It("builds volumes from config", func() {
    87  			v := hsmConfig.GetVolumes()
    88  			Expect(v).To(ContainElements(
    89  				corev1.Volume{
    90  					Name: "hsmcrypto",
    91  					VolumeSource: corev1.VolumeSource{
    92  						Secret: &corev1.SecretVolumeSource{
    93  							SecretName: "hsmcrypto",
    94  							Items: []corev1.KeyToPath{
    95  								{
    96  									Key:  "cert.pem",
    97  									Path: "cert.pem",
    98  								},
    99  								{
   100  									Key:  "key.pem",
   101  									Path: "key.pem",
   102  								},
   103  							},
   104  						},
   105  					},
   106  				},
   107  				corev1.Volume{
   108  					Name: "hsmconfig",
   109  					VolumeSource: corev1.VolumeSource{
   110  						Secret: &corev1.SecretVolumeSource{
   111  							SecretName: "hsmcrypto",
   112  						},
   113  					},
   114  				},
   115  			))
   116  		})
   117  	})
   118  
   119  	Context("env vars", func() {
   120  		It("builds env vars from config", func() {
   121  			envs := hsmConfig.GetEnvs()
   122  			Expect(envs).To(ContainElements(
   123  				corev1.EnvVar{
   124  					Name:  "env1",
   125  					Value: "env1value",
   126  				},
   127  			))
   128  		})
   129  	})
   130  
   131  	Context("build pull secret", func() {
   132  		It("returns empty LocalObjectReference obj if pull secret not passed in config", func() {
   133  			ps := hsmConfig.BuildPullSecret()
   134  			Expect(ps).To(Equal(corev1.LocalObjectReference{}))
   135  		})
   136  
   137  		It("returns LocalObjectReference with pull secret from config", func() {
   138  			hsmConfig.Library.Auth = &config.Auth{
   139  				ImagePullSecret: "pullsecret",
   140  			}
   141  			ps := hsmConfig.BuildPullSecret()
   142  			Expect(ps.Name).To(Equal("pullsecret"))
   143  		})
   144  	})
   145  })