github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/offering/k8s/console/override/ingress_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 networkingv1 "k8s.io/api/networking/v1" 25 26 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 27 "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" 28 "github.com/IBM-Blockchain/fabric-operator/pkg/offering/k8s/console/override" 29 "github.com/IBM-Blockchain/fabric-operator/pkg/util" 30 ) 31 32 var _ = Describe("K8s Console Ingress Overrides", func() { 33 var ( 34 err error 35 overrider *override.Override 36 instance *current.IBPConsole 37 ingress *networkingv1.Ingress 38 consolehost string 39 ) 40 41 BeforeEach(func() { 42 overrider = &override.Override{} 43 instance = ¤t.IBPConsole{ 44 Spec: current.IBPConsoleSpec{ 45 NetworkInfo: ¤t.NetworkInfo{ 46 Domain: "test.domain", 47 }, 48 }, 49 } 50 ingress, err = util.GetIngressFromFile("../../../../../definitions/console/ingress.yaml") 51 Expect(err).NotTo(HaveOccurred()) 52 53 consolehost = instance.Namespace + "-" + instance.Name + "-console" + "." + instance.Spec.NetworkInfo.Domain 54 }) 55 56 Context("create", func() { 57 It("appropriately overrides the respective values for ingress", func() { 58 err := overrider.Ingress(instance, ingress, resources.Create) 59 Expect(err).NotTo(HaveOccurred()) 60 61 By("setting rule", func() { 62 pathType := networkingv1.PathTypeImplementationSpecific 63 Expect(ingress.Spec.Rules).To(HaveLen(1)) 64 Expect(ingress.Spec.Rules[0]).To(Equal(networkingv1.IngressRule{ 65 Host: consolehost, 66 IngressRuleValue: networkingv1.IngressRuleValue{ 67 HTTP: &networkingv1.HTTPIngressRuleValue{ 68 Paths: []networkingv1.HTTPIngressPath{ 69 networkingv1.HTTPIngressPath{ 70 Backend: networkingv1.IngressBackend{ 71 Service: &networkingv1.IngressServiceBackend{ 72 Name: instance.GetName(), 73 Port: networkingv1.ServiceBackendPort{ 74 Name: "optools", 75 }, 76 }, 77 }, 78 Path: "/", 79 PathType: &pathType, 80 }, 81 }, 82 }, 83 }, 84 })) 85 }) 86 87 By("setting TLS hosts", func() { 88 Expect(ingress.Spec.TLS).To(HaveLen(1)) 89 Expect(ingress.Spec.TLS[0].Hosts).To(Equal([]string{consolehost})) 90 }) 91 }) 92 }) 93 })