|
| 1 | +// ------------------------------------------------------------------------------------------- |
| 2 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +// -------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +package appgw |
| 7 | + |
| 8 | +import ( |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network" |
| 12 | + "github.com/Azure/go-autorest/autorest/to" |
| 13 | + . "github.com/onsi/ginkgo" |
| 14 | + . "github.com/onsi/gomega" |
| 15 | + "k8s.io/api/extensions/v1beta1" |
| 16 | +) |
| 17 | + |
| 18 | +func TestHealthProbes(t *testing.T) { |
| 19 | + RegisterFailHandler(Fail) |
| 20 | + RunSpecs(t, "Test setting up App Gateway health probes") |
| 21 | +} |
| 22 | + |
| 23 | +var _ = Describe("configure App Gateway health probes", func() { |
| 24 | + Context("create probes", func() { |
| 25 | + cb := makeConfigBuilderTestFixture(nil) |
| 26 | + |
| 27 | + endpoints := makeEndpointsFixture() |
| 28 | + _ = cb.k8sContext.Caches.Endpoints.Add(endpoints) |
| 29 | + |
| 30 | + service := makeServiceFixture(*makeServicePorts()...) |
| 31 | + _ = cb.k8sContext.Caches.Service.Add(service) |
| 32 | + |
| 33 | + pod := makePodFixture(testFixturesServiceName, testFixturesNamespace, testFixturesContainerName, testFixturesContainerPort) |
| 34 | + _ = cb.k8sContext.Caches.Pods.Add(pod) |
| 35 | + |
| 36 | + ingressList := []*v1beta1.Ingress{ |
| 37 | + makeIngressFixture(), |
| 38 | + } |
| 39 | + |
| 40 | + // !! Action !! |
| 41 | + _, _ = cb.HealthProbesCollection(ingressList) |
| 42 | + actual := cb.appGwConfig.Probes |
| 43 | + |
| 44 | + // We expect our health probe configurator to have arrived at this final setup |
| 45 | + defaultProbe := network.ApplicationGatewayProbe{ |
| 46 | + |
| 47 | + ApplicationGatewayProbePropertiesFormat: &network.ApplicationGatewayProbePropertiesFormat{ |
| 48 | + Protocol: network.HTTP, |
| 49 | + Host: to.StringPtr("localhost"), |
| 50 | + Path: to.StringPtr("/"), |
| 51 | + Interval: to.Int32Ptr(30), |
| 52 | + Timeout: to.Int32Ptr(30), |
| 53 | + UnhealthyThreshold: to.Int32Ptr(3), |
| 54 | + PickHostNameFromBackendHTTPSettings: nil, |
| 55 | + MinServers: nil, |
| 56 | + Match: nil, |
| 57 | + ProvisioningState: nil, |
| 58 | + }, |
| 59 | + Name: to.StringPtr("k8s-ag-ingress-defaultprobe"), |
| 60 | + Etag: nil, |
| 61 | + Type: nil, |
| 62 | + ID: nil, |
| 63 | + } |
| 64 | + probeForHost := network.ApplicationGatewayProbe{ |
| 65 | + ApplicationGatewayProbePropertiesFormat: &network.ApplicationGatewayProbePropertiesFormat{ |
| 66 | + Protocol: network.HTTP, |
| 67 | + Host: to.StringPtr(testFixturesHost), |
| 68 | + Path: to.StringPtr(testFixturesURLPath), |
| 69 | + Interval: to.Int32Ptr(30), |
| 70 | + Timeout: to.Int32Ptr(30), |
| 71 | + UnhealthyThreshold: to.Int32Ptr(3), |
| 72 | + PickHostNameFromBackendHTTPSettings: nil, |
| 73 | + MinServers: nil, |
| 74 | + Match: nil, |
| 75 | + ProvisioningState: nil, |
| 76 | + }, |
| 77 | + Name: to.StringPtr("k8s-ag-ingress---service-name---443-pb---name--"), |
| 78 | + Etag: nil, |
| 79 | + Type: nil, |
| 80 | + ID: nil, |
| 81 | + } |
| 82 | + |
| 83 | + probeForOtherHost := network.ApplicationGatewayProbe{ |
| 84 | + ApplicationGatewayProbePropertiesFormat: &network.ApplicationGatewayProbePropertiesFormat{ |
| 85 | + Protocol: network.HTTP, |
| 86 | + Host: to.StringPtr(testFixturesHost), |
| 87 | + Path: to.StringPtr(testFixturesURLPath), |
| 88 | + Interval: to.Int32Ptr(20), |
| 89 | + Timeout: to.Int32Ptr(5), |
| 90 | + UnhealthyThreshold: to.Int32Ptr(3), |
| 91 | + PickHostNameFromBackendHTTPSettings: nil, |
| 92 | + MinServers: nil, |
| 93 | + Match: nil, |
| 94 | + ProvisioningState: nil, |
| 95 | + }, |
| 96 | + Name: to.StringPtr("k8s-ag-ingress---service-name---80-pb---name--"), |
| 97 | + Etag: nil, |
| 98 | + Type: nil, |
| 99 | + ID: nil, |
| 100 | + } |
| 101 | + |
| 102 | + It("should have exactly 3 records", func() { |
| 103 | + Expect(len(*actual)).To(Equal(3)) |
| 104 | + }) |
| 105 | + |
| 106 | + It("should have created 1 default probe", func() { |
| 107 | + Expect(*actual).To(ContainElement(defaultProbe)) |
| 108 | + }) |
| 109 | + |
| 110 | + It("should have created 1 probe for Host", func() { |
| 111 | + Expect(*actual).To(ContainElement(probeForHost)) |
| 112 | + }) |
| 113 | + |
| 114 | + It("should have created 1 probe for OtherHost", func() { |
| 115 | + Expect(*actual).To(ContainElement(probeForOtherHost)) |
| 116 | + }) |
| 117 | + }) |
| 118 | +}) |
0 commit comments