Skip to content

Commit

Permalink
Updating the testURL and the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ChandraPrakash committed Nov 26, 2018
1 parent cc3e8d8 commit 7000aa9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 14 additions & 2 deletions pkg/kube/wrappers/ingress-wrapper.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/kube/wrappers/ingress-wrapper_test.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -99,15 +99,15 @@ 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{
ingress: createIngressObjectWithPath("testIngress", "test", testUrl, "/*"),
namespace: "test",
kubeClient: getTestKubeClient(),
},
want: "http://testurl.stackator.com/",
want: "http://testurl.stackator.com:80/",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 7000aa9

Please sign in to comment.