MCPcopy Index your code
hub / github.com/docker/cli / TestConfigContextFormatWrite

Function TestConfigContextFormatWrite

cli/command/config/formatter_test.go:14–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestConfigContextFormatWrite(t *testing.T) {
15 // Check default output format (verbose and non-verbose mode) for table headers
16 cases := []struct {
17 context formatter.Context
18 expected string
19 }{
20 // Errors
21 {
22 formatter.Context{Format: "{{InvalidFunction}}"},
23 `template parsing error: template: :1: function "InvalidFunction" not defined`,
24 },
25 {
26 formatter.Context{Format: "{{nil}}"},
27 `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
28 },
29 // Table format
30 {
31 formatter.Context{Format: newFormat("table", false)},
32 `ID NAME CREATED UPDATED
331 passwords Less than a second ago Less than a second ago
342 id_rsa Less than a second ago Less than a second ago
35`,
36 },
37 {
38 formatter.Context{Format: newFormat("table {{.Name}}", true)},
39 `NAME
40passwords
41id_rsa
42`,
43 },
44 {
45 formatter.Context{Format: newFormat("{{.ID}}-{{.Name}}", false)},
46 `1-passwords
472-id_rsa
48`,
49 },
50 }
51
52 res := client.ConfigListResult{
53 Items: []swarm.Config{
54 {
55 ID: "1",
56 Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
57 Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "passwords"}},
58 },
59 {
60 ID: "2",
61 Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
62 Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}},
63 },
64 },
65 }
66 for _, tc := range cases {
67 t.Run(string(tc.context.Format), func(t *testing.T) {
68 var out bytes.Buffer
69 tc.context.Output = &out
70 if err := formatWrite(tc.context, res); err != nil {
71 assert.ErrorContains(t, err, tc.expected)

Callers

nothing calls this directly

Calls 3

newFormatFunction · 0.70
formatWriteFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…