MCPcopy
hub / github.com/docker/docker-agent / TestRunAliasListCommand_JSONFormat

Function TestRunAliasListCommand_JSONFormat

cmd/root/alias_test.go:16–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestRunAliasListCommand_JSONFormat(t *testing.T) {
17 // Not parallel: SetConfigDir mutates process-global state.
18 dir := t.TempDir()
19 paths.SetConfigDir(dir)
20 t.Cleanup(func() { paths.SetConfigDir("") })
21
22 cfg, err := userconfig.Load()
23 require.NoError(t, err)
24 require.NoError(t, cfg.SetAlias("build", &userconfig.Alias{Path: "./build.yaml", Yolo: true, Model: "anthropic/claude"}))
25 require.NoError(t, cfg.SetAlias("deploy", &userconfig.Alias{Path: "oci://deploy"}))
26 require.NoError(t, cfg.Save())
27
28 var buf bytes.Buffer
29 cmd := &cobra.Command{}
30 cmd.SetOut(&buf)
31 require.NoError(t, runAliasListCommand(cmd, nil, true))
32
33 var entries []aliasListEntry
34 require.NoError(t, json.Unmarshal(buf.Bytes(), &entries))
35 require.Len(t, entries, 2)
36
37 // Entries are sorted by name for deterministic output.
38 assert.Equal(t, "build", entries[0].Name)
39 assert.Equal(t, "./build.yaml", entries[0].Path)
40 assert.True(t, entries[0].Yolo)
41 assert.Equal(t, "anthropic/claude", entries[0].Model)
42
43 assert.Equal(t, "deploy", entries[1].Name)
44 assert.Equal(t, "oci://deploy", entries[1].Path)
45 assert.False(t, entries[1].Yolo)
46
47 // Zero-valued options are omitted from the JSON output.
48 assert.NotContains(t, buf.String(), `"sandbox"`)
49}
50
51func TestRunAliasListCommand_JSONFormatEmpty(t *testing.T) {
52 // Not parallel: SetConfigDir mutates process-global state.

Callers

nothing calls this directly

Calls 9

BytesMethod · 0.95
StringMethod · 0.95
SetConfigDirFunction · 0.92
LoadFunction · 0.92
runAliasListCommandFunction · 0.85
SetAliasMethod · 0.80
SaveMethod · 0.80
CleanupMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected