MCPcopy Create free account
hub / github.com/algolia/cli / TestRunOpenCmd_ListJSONOutput

Function TestRunOpenCmd_ListJSONOutput

pkg/cmd/open/open_test.go:286–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

284}
285
286func TestRunOpenCmd_ListJSONOutput(t *testing.T) {
287 t.Setenv("ALGOLIA_APPLICATION_ID", "")
288
289 io, _, stdout, _ := iostreams.Test()
290
291 cfg := test.NewConfigStubWithProfiles([]*config.Profile{
292 {Name: "default", ApplicationID: "APP123", APIKey: "key", Default: true},
293 })
294
295 opts, opened, authed := newTestOptions(io, cfg)
296 opts.List = true
297 withOutputFormat(opts, "json")
298
299 err := runOpenCmd(opts)
300 require.NoError(t, err)
301
302 var entries []pageEntry
303 require.NoError(t, json.Unmarshal(stdout.Bytes(), &entries))
304 assert.Len(t, entries, len(resourceURLs)+len(dashboardTargets))
305
306 byName := make(map[string]pageEntry, len(entries))
307 for _, e := range entries {
308 byName[e.Shortcut] = e
309 }
310
311 assert.Equal(
312 t,
313 pageEntry{
314 Shortcut: "billing",
315 URL: "https://dashboard.algolia.com/account/billing/details?applicationId=APP123",
316 RequiresLogin: true,
317 },
318 byName["billing"],
319 )
320 assert.Equal(
321 t,
322 pageEntry{Shortcut: "docs", URL: "https://algolia.com/doc/"},
323 byName["docs"],
324 )
325
326 // Structured output never opens a browser or signs in.
327 assert.False(t, *authed)
328 assert.Empty(t, *opened)
329}
330
331func TestRunOpenCmd_SingleShortcutJSONOutput(t *testing.T) {
332 io, _, stdout, _ := iostreams.Test()

Callers

nothing calls this directly

Calls 5

TestFunction · 0.92
newTestOptionsFunction · 0.85
withOutputFormatFunction · 0.85
runOpenCmdFunction · 0.85

Tested by

no test coverage detected