Skip to content
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

Merged
merged 4 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/minikube/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func WaitAndMaybeOpenService(api libmachine.API, namespace string, service strin
chkSVC := func() error { return CheckService(namespace, service) }

if err := retry.Expo(chkSVC, time.Duration(interval)*time.Second, time.Duration(wait)*time.Second); err != nil {
return errors.Wrapf(err, "Could not find finalized endpoint being pointed to by %s", service)
return errors.Wrapf(err, "Service %s was not found in %q namespace. You may select another namespace by using 'minikube service %s -n <namespace>", service, namespace, service)
}

serviceURL, err := GetServiceURLsForService(api, namespace, service, urlTemplate)
Expand Down
72 changes: 72 additions & 0 deletions pkg/minikube/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ var serviceNamespaces = map[string]typed_core.ServiceInterface{
"default": defaultNamespaceServiceInterface,
}

var serviceNamespaceOther = 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: "cannot_be_found_namespace",
Labels: map[string]string{"mock": "mock"},
},
Spec: core.ServiceSpec{
Ports: []core.ServicePort{},
},
},
},
},
}

var defaultNamespaceServiceInterface = &MockServiceInterface{
ServiceList: &core.ServiceList{
Items: []core.Service{
Expand Down Expand Up @@ -893,3 +914,54 @@ func TestWaitAndMaybeOpenService(t *testing.T) {
})
}
}

func TestWaitAndMaybeOpenServiceForNotDefaultNamspace(t *testing.T) {
defaultAPI := &tests.MockAPI{
FakeStore: tests.FakeStore{
Hosts: map[string]*host.Host{
config.GetMachineName(): {
Name: config.GetMachineName(),
Driver: &tests.MockDriver{},
},
},
},
}
defaultTemplate := template.Must(template.New("svc-template").Parse("http://{{.IP}}:{{.Port}}"))

var tests = []struct {
description string
api libmachine.API
namespace string
service string
expected []string
urlMode bool
https bool
err bool
}{
{
description: "correctly return empty serviceURLs",
namespace: "default",
service: "non-namespace-dashboard-no-ports",
api: defaultAPI,
expected: []string{},
err: true,
},
}
defer revertK8sClient(K8s)
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
K8s = &MockClientGetter{
servicesMap: serviceNamespaceOther,
endpointsMap: endpointNamespaces,
}
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0)
if test.err && err == nil {
t.Fatalf("WaitAndMaybeOpenService expected to fail for test: %v", test)
}
if !test.err && err != nil {
t.Fatalf("WaitAndMaybeOpenService not expected to fail but got err: %v", err)
}

})
}
}
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TESTSUITE="${TESTSUITE:-all}" # if env variable not set run all the tests
exitcode=0

if [[ "$TESTSUITE" = "lint" ]] || [[ "$TESTSUITE" = "all" ]]
then
then
echo "= make lint ============================================================="
make -s lint-ci && echo ok || ((exitcode += 4))
echo "= go mod ================================================================"
Expand Down