From 7000aa9660a9eec2a858541df0f31e5b56853119 Mon Sep 17 00:00:00 2001 From: ChandraPrakash Date: Mon, 26 Nov 2018 21:46:36 +0530 Subject: [PATCH] Updating the testURL and the wrapper --- pkg/kube/wrappers/ingress-wrapper.go | 16 ++++++++++++++-- pkg/kube/wrappers/ingress-wrapper_test.go | 16 ++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pkg/kube/wrappers/ingress-wrapper.go b/pkg/kube/wrappers/ingress-wrapper.go index 1bfc0852..1bcc78f3 100644 --- a/pkg/kube/wrappers/ingress-wrapper.go +++ b/pkg/kube/wrappers/ingress-wrapper.go @@ -58,7 +58,19 @@ func (iw *IngressWrapper) getIngressSubPathWithPort() string { port := iw.getIngressPort() subPath := iw.getIngressSubPath() - return port + subPath + if port != nil { + if subPath != nil { + return port + subPath + } else { + return port + "/" + } + } else { + if subPath != nil { + return "80" + subPath + } else { + return "80/" + } + } } func (iw *IngressWrapper) getIngressPort() string { @@ -118,7 +130,7 @@ func (iw *IngressWrapper) GetURL() string { } else { // Append port + ingressSubPath ingressSubPathWithPort := iw.getIngressSubPathWithPort() - u.Path = u.Path + ":" + strings.Split(ingressSubPathWithPort, "/")[0] + u.Path = strings.TripSuffix(u.Path, "/") + ":" + strings.Split(ingressSubPathWithPort, "/")[0] u.Path = path.Join(u.Path, strings.Join(strings.Split(iw.getIngressSubPathWithPort(), "/")[1:], "/")) // Find pod by backtracking ingress -> service -> pod diff --git a/pkg/kube/wrappers/ingress-wrapper_test.go b/pkg/kube/wrappers/ingress-wrapper_test.go index 5a9d4028..da949f46 100644 --- a/pkg/kube/wrappers/ingress-wrapper_test.go +++ b/pkg/kube/wrappers/ingress-wrapper_test.go @@ -11,7 +11,7 @@ import ( ) const ( - testUrl = "testurl.stackator.com/" + testUrl = "testurl.stackator.com" ) func createIngressObjectWithPath(ingressName string, namespace string, url string, path string) *v1beta1.Ingress { @@ -54,7 +54,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "http://testurl.stackator.com/", + want: "http://testurl.stackator.com:80/", }, { name: "TestGetUrlWithHelloPath", @@ -63,7 +63,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "http://testurl.stackator.com/hello", + want: "http://testurl.stackator.com:80/hello", }, { name: "TestGetUrlWithNoPath", @@ -72,7 +72,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "http://testurl.stackator.com/", + want: "http://testurl.stackator.com:80/", }, { name: "TestGetUrlWithForceHTTPSAnnotation", @@ -81,7 +81,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "https://testurl.stackator.com/", + want: "https://testurl.stackator.com:80/", }, { name: "TestGetUrlWithForceHTTPSAnnotationOff", @@ -90,7 +90,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "http://testurl.stackator.com/", + want: "http://testurl.stackator.com:80/", }, { name: "TestGetUrlWithOverridePathAnnotation", @@ -99,7 +99,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "http://testurl.stackator.com/overriden-path", + want: "http://testurl.stackator.com:80/overriden-path", }, { name: "TestGetUrlWithWildCardInPath", fields: fields{ @@ -107,7 +107,7 @@ func TestIngressWrapper_getURL(t *testing.T) { namespace: "test", kubeClient: getTestKubeClient(), }, - want: "http://testurl.stackator.com/", + want: "http://testurl.stackator.com:80/", }, } for _, tt := range tests {