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