-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make error message more human readable #5563
Changes from 2 commits
197215f
75ce59d
733f7bc
10ff44e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,27 @@ var serviceNamespaces = map[string]typed_core.ServiceInterface{ | |
"default": defaultNamespaceServiceInterface, | ||
} | ||
|
||
var nondefaultserviceNamespaces = map[string]typed_core.ServiceInterface{ | ||
"default": nondefaultNamespaceServiceInterface, | ||
} | ||
|
||
var nondefaultNamespaceServiceInterface = &MockServiceInterface{ | ||
ServiceList: &core.ServiceList{ | ||
Items: []core.Service{ | ||
{ | ||
ObjectMeta: meta.ObjectMeta{ | ||
Name: "non-namespace-dashboard-no-ports", | ||
Namespace: "non-default", | ||
Labels: map[string]string{"mock": "mock"}, | ||
}, | ||
Spec: core.ServiceSpec{ | ||
Ports: []core.ServicePort{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var defaultNamespaceServiceInterface = &MockServiceInterface{ | ||
ServiceList: &core.ServiceList{ | ||
Items: []core.Service{ | ||
|
@@ -824,6 +845,7 @@ func TestWaitAndMaybeOpenService(t *testing.T) { | |
urlMode bool | ||
https bool | ||
err bool | ||
nondefault bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bools should never be negative or have a name that starts with with Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look into the test again and refactor to make it more readable for code structure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor the code to split out the test on it's own to make it more easier to understand for other. Let me know what you think ?. Thanks |
||
}{ | ||
/* { | ||
description: "no host", | ||
|
@@ -841,13 +863,15 @@ func TestWaitAndMaybeOpenService(t *testing.T) { | |
api: defaultAPI, | ||
https: true, | ||
expected: []string{"http://127.0.0.1:1111", "http://127.0.0.1:2222"}, | ||
nondefault: false, | ||
}, | ||
{ | ||
description: "correctly return serviceURLs, no https, no url mode", | ||
namespace: "default", | ||
service: "mock-dashboard", | ||
api: defaultAPI, | ||
expected: []string{"http://127.0.0.1:1111", "http://127.0.0.1:2222"}, | ||
nondefault: false, | ||
}, | ||
{ | ||
description: "correctly return serviceURLs, no https, url mode", | ||
|
@@ -856,6 +880,7 @@ func TestWaitAndMaybeOpenService(t *testing.T) { | |
api: defaultAPI, | ||
urlMode: true, | ||
expected: []string{"http://127.0.0.1:1111", "http://127.0.0.1:2222"}, | ||
nondefault: false, | ||
}, | ||
{ | ||
description: "correctly return serviceURLs, https, url mode", | ||
|
@@ -865,6 +890,7 @@ func TestWaitAndMaybeOpenService(t *testing.T) { | |
urlMode: true, | ||
https: true, | ||
expected: []string{"http://127.0.0.1:1111", "http://127.0.0.1:2222"}, | ||
nondefault: false, | ||
}, | ||
{ | ||
description: "correctly return empty serviceURLs", | ||
|
@@ -873,14 +899,31 @@ func TestWaitAndMaybeOpenService(t *testing.T) { | |
api: defaultAPI, | ||
expected: []string{}, | ||
err: true, | ||
nondefault: false, | ||
}, | ||
{ | ||
description: "correctly return empty serviceURLs", | ||
namespace: "default", | ||
service: "non-namespace-dashboard-no-ports", | ||
api: defaultAPI, | ||
expected: []string{}, | ||
err: true, | ||
nondefault: true, | ||
}, | ||
} | ||
defer revertK8sClient(K8s) | ||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
K8s = &MockClientGetter{ | ||
servicesMap: serviceNamespaces, | ||
endpointsMap: endpointNamespaces, | ||
if test.nondefault { | ||
K8s = &MockClientGetter{ | ||
servicesMap: nondefaultserviceNamespaces, | ||
endpointsMap: endpointNamespaces, | ||
} | ||
} else { | ||
K8s = &MockClientGetter{ | ||
servicesMap: serviceNamespaces, | ||
endpointsMap: endpointNamespaces, | ||
} | ||
} | ||
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0) | ||
if test.err && err == nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this text, but it should detect if
namespace
is default, otherwise the error message doesn't make much sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made changes to the string to include the service name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tstromberg any feedback ? Thanks