Skip to content

Commit

Permalink
Updating the test and ingress wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ChandraPrakash committed Nov 22, 2018
1 parent 654f72c commit cc3e9f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions pkg/kube/wrappers/ingress-wrapper.go
Expand Up @@ -4,8 +4,8 @@ import (
"log"
"net/url"
"path"
"strings"
"reflect"
"strings"

"github.com/stakater/IngressMonitorController/pkg/constants"
"k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions pkg/kube/wrappers/ingress-wrapper_test.go
Expand Up @@ -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) {
Expand Down

0 comments on commit cc3e9f3

Please sign in to comment.