diff --git a/cli/cmd/dashboard.go b/cli/cmd/dashboard.go index 9a7054f..665162c 100644 --- a/cli/cmd/dashboard.go +++ b/cli/cmd/dashboard.go @@ -1,6 +1,8 @@ package cmd import ( + "fmt" + "github.com/spf13/cobra" ) @@ -10,7 +12,15 @@ func newCmdDashboard(cfg *config, openURL openURL) *cobra.Command { Args: cobra.NoArgs, Short: "Open the Buoyant Cloud dashboard", RunE: func(cmd *cobra.Command, args []string) error { - return openURL(cfg.bcloudServer) + fmt.Fprintln(cfg.stdout, "Opening Buoyant Cloud dashboard in the default browser") + + err := openURL(cfg.bcloudServer) + if err != nil { + fmt.Fprintln(cfg.stderr, "Failed to open dashboard automatically") + fmt.Fprintf(cfg.stderr, "Visit %s in your browser to view the dashboard\n", cfg.bcloudServer) + } + + return nil }, } } diff --git a/cli/cmd/dashboard_test.go b/cli/cmd/dashboard_test.go index fe86bcd..31851e7 100644 --- a/cli/cmd/dashboard_test.go +++ b/cli/cmd/dashboard_test.go @@ -1,11 +1,20 @@ package cmd import ( + "bytes" + "errors" + "strings" "testing" ) func TestDashboard(t *testing.T) { - cfg := &config{bcloudServer: "http://example.com"} + stdout := &bytes.Buffer{} + stderr := &bytes.Buffer{} + cfg := &config{ + stdout: stdout, + stderr: stderr, + bcloudServer: "http://example.com", + } var openedUrl string mockOpen := func(url string) error { @@ -23,3 +32,27 @@ func TestDashboard(t *testing.T) { t.Fatalf("Expected to open url %s, Got %s", cfg.bcloudServer, openedUrl) } } + +func TestDashboardFailure(t *testing.T) { + stdout := &bytes.Buffer{} + stderr := &bytes.Buffer{} + cfg := &config{ + stdout: stdout, + stderr: stderr, + bcloudServer: "http://example.com", + } + + mockOpen := func(string) error { + return errors.New("browser failuer") + } + + cmd := newCmdDashboard(cfg, mockOpen) + err := cmd.RunE(cmd, nil) + if err != nil { + t.Error(err) + } + + if !strings.Contains(stderr.String(), cfg.bcloudServer) { + t.Errorf("Expected stderr to contain [%s], Got: [%s]", cfg.bcloudServer, stderr.String()) + } +}