Skip to content

Commit

Permalink
Add boolean to disable opening browser during test
Browse files Browse the repository at this point in the history
The WaitAndMaybeOpenService(..) method allow user to open the service
url in a browser when found, this create issue during testing as it's
opening browser and consuming resources.

The fix is to introduce a boolean flag allowing the caller to specify
whether to just print out the url or open a browser window
  • Loading branch information
nanikjava committed Oct 24, 2019
1 parent 5ba4a7d commit f4e2c7b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/open.go
Expand Up @@ -95,7 +95,7 @@ You can add one by annotating a service with the label {{.labelName}}:{{.addonNa
}
for i := range serviceList.Items {
svc := serviceList.Items[i].ObjectMeta.Name
if err := service.WaitAndMaybeOpenService(api, namespace, svc, addonsURLTemplate, addonsURLMode, https, wait, interval); err != nil {
if err := service.WaitAndMaybeOpenService(api, namespace, svc, addonsURLTemplate, addonsURLMode, https, wait, interval, true); err != nil {
exit.WithCodeT(exit.Unavailable, "Wait failed: {{.error}}", out.V{"error": err})
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/service.go
Expand Up @@ -69,7 +69,7 @@ var serviceCmd = &cobra.Command{
os.Exit(1)
}
err = service.WaitAndMaybeOpenService(api, namespace, svc,
serviceURLTemplate, serviceURLMode, https, wait, interval)
serviceURLTemplate, serviceURLMode, https, wait, interval, true)
if err != nil {
exit.WithError("Error opening service", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/service/service.go
Expand Up @@ -267,7 +267,7 @@ func PrintServiceList(writer io.Writer, data [][]string) {

// WaitAndMaybeOpenService waits for a service, and opens it when running
func WaitAndMaybeOpenService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool,
wait int, interval int) error {
wait int, interval int, openbrowser bool) error {
// Convert "Amount of time to wait" and "interval of each check" to attempts
if interval == 0 {
interval = 1
Expand Down Expand Up @@ -301,7 +301,7 @@ func WaitAndMaybeOpenService(api libmachine.API, namespace string, service strin
for _, bareURLString := range serviceURL.URLs {
urlString, isHTTPSchemedURL := OptionallyHTTPSFormattedURLString(bareURLString, https)

if urlMode || !isHTTPSchemedURL {
if urlMode || !isHTTPSchemedURL || !openbrowser {
out.T(out.Empty, urlString)
} else {
out.T(out.Celebrate, "Opening kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": service})
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/service/service_test.go
Expand Up @@ -903,7 +903,7 @@ func TestWaitAndMaybeOpenService(t *testing.T) {
servicesMap: serviceNamespaces,
endpointsMap: endpointNamespaces,
}
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0)
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0, false)
if test.err && err == nil {
t.Fatalf("WaitAndMaybeOpenService expected to fail for test: %v", test)
}
Expand Down Expand Up @@ -954,7 +954,7 @@ func TestWaitAndMaybeOpenServiceForNotDefaultNamspace(t *testing.T) {
servicesMap: serviceNamespaceOther,
endpointsMap: endpointNamespaces,
}
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0)
err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0, false)
if test.err && err == nil {
t.Fatalf("WaitAndMaybeOpenService expected to fail for test: %v", test)
}
Expand Down

0 comments on commit f4e2c7b

Please sign in to comment.