Skip to content

Commit

Permalink
Browser-opening test, sorta
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Dec 17, 2024
1 parent 38a1b6b commit 67a6584
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/24454.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Added UI URL hints to the end of common CLI commands and a -ui flag to auto-open them
```
32 changes: 26 additions & 6 deletions command/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,30 @@ func TestMeta_ShowUIPath_CLIURLLinksDisabled(t *testing.T) {
must.StrNotContains(t, hint, url+"/ui/jobs")
}

// TODO: invalid/edge cases
// - unknown command
// - missing required params
// - invalid path params
// - --output flag on job run
func TestMeta_ShowUIPath_BrowserOpening(t *testing.T) {
ci.Parallel(t)

server, client, url := testServer(t, true, func(c *agent.Config) {
c.UI.CLIURLLinks = pointer.Of(true)
})
defer server.Shutdown()
waitForNodes(t, client)

ui := cli.NewMockUi()

m := &Meta{
Ui: ui,
flagAddress: url,
}

hint, err := m.showUIPath(UIHintContext{
Command: "job status",
OpenURL: true,
})
must.NoError(t, err)
must.StrContains(t, hint, url+"/ui/jobs")

// TODO: browser opening tests
// Not a perfect test, but it's a start: make sure showUIPath isn't warning about
// being unable to open the browser.
must.StrNotContains(t, ui.ErrorWriter.String(), "Failed to open browser")
}
2 changes: 0 additions & 2 deletions command/plugin_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,5 @@ func (c *PluginStatusCommand) Run(args []string) int {

// Extend this section with other plugin implementations

// TODO: add UI Hints

return 0
}

0 comments on commit 67a6584

Please sign in to comment.