From cc3e9f3c77bd9e839419519d078e5c604641bfb0 Mon Sep 17 00:00:00 2001 From: ChandraPrakash Date: Thu, 22 Nov 2018 17:57:52 +0530 Subject: [PATCH] Updating the test and ingress wrapper --- pkg/kube/wrappers/ingress-wrapper.go | 10 ++++------ pkg/kube/wrappers/ingress-wrapper_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/kube/wrappers/ingress-wrapper.go b/pkg/kube/wrappers/ingress-wrapper.go index abeaebb1..f8926c5e 100644 --- a/pkg/kube/wrappers/ingress-wrapper.go +++ b/pkg/kube/wrappers/ingress-wrapper.go @@ -4,8 +4,8 @@ import ( "log" "net/url" "path" - "strings" "reflect" + "strings" "github.com/stakater/IngressMonitorController/pkg/constants" "k8s.io/api/extensions/v1beta1" @@ -67,8 +67,7 @@ func (iw *IngressWrapper) getIngressPort() string { if rule.HTTP.Paths != nil && len(rule.HTTP.Paths) > 0 { if reflect.TypeOf(rule.HTTP.Paths[0].Backend.ServicePort) == "string" { return "80" - } - else { + } else { return rule.HTTP.Paths[0].Backend.ServicePort.StrVal } } @@ -82,8 +81,7 @@ func (iw *IngressWrapper) getIngressSubPath() string { if rule.HTTP.Paths != nil && len(rule.HTTP.Paths) > 0 { if strings.ContainsAny(rule.HTTP.Paths[0].Path, "*") { return strings.TrimRight(rule.HTTP.Paths[0].Path, "*") - } - else { + } else { return rule.HTTP.Paths[0].Path } } @@ -121,7 +119,7 @@ func (iw *IngressWrapper) GetURL() string { // Append port + ingressSubPath ingressSubPathWithPort := iw.getIngressSubPathWithPort() u.Path = u.Path + ":" + strings.Split(ingressSubPathWithPort, "/")[0] - u.Path = path.Join(u.Path, strings.Join(strings.Split(iw,getIngressSubPathWithPort(), "/")[1:], "/")) + u.Path = path.Join(u.Path, strings.Join(strings.Split(iw, getIngressSubPathWithPort(), "/")[1:], "/")) // Find pod by backtracking ingress -> service -> pod healthEndpoint, exists := iw.tryGetHealthEndpointFromIngress() diff --git a/pkg/kube/wrappers/ingress-wrapper_test.go b/pkg/kube/wrappers/ingress-wrapper_test.go index d18b7355..5a9d4028 100644 --- a/pkg/kube/wrappers/ingress-wrapper_test.go +++ b/pkg/kube/wrappers/ingress-wrapper_test.go @@ -100,15 +100,15 @@ func TestIngressWrapper_getURL(t *testing.T) { kubeClient: getTestKubeClient(), }, want: "http://testurl.stackator.com/overriden-path", - },{ + }, { name: "TestGetUrlWithWildCardInPath", fields: fields{ - ingress: createIngressObjectWithPath("testIngress", "test", testUrl, "/*"), - namespace: "test", + ingress: createIngressObjectWithPath("testIngress", "test", testUrl, "/*"), + namespace: "test", kubeClient: getTestKubeClient(), }, want: "http://testurl.stackator.com/", - } + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {