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

Function TestStackContextWrite

cli/command/stack/list_formatter_test.go:11–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestStackContextWrite(t *testing.T) {
12 tests := []struct {
13 name string
14 format formatter.Format
15 expected string
16 }{
17 {
18 name: "invalid function",
19 format: `{{InvalidFunction}}`,
20 expected: `template parsing error: template: :1: function "InvalidFunction" not defined`,
21 },
22 {
23 name: "invalid placeholder",
24 format: `{{nil}}`,
25 expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
26 },
27 {
28 name: "table format",
29 format: stackTableFormat,
30 expected: `NAME SERVICES
31baz 2
32bar 1
33`,
34 },
35 {
36 name: "custom table format",
37 format: `table {{.Name}}`,
38 expected: `NAME
39baz
40bar
41`,
42 },
43 {
44 name: "custom format",
45 format: `{{.Name}}`,
46 expected: `baz
47bar
48`,
49 },
50 }
51
52 for _, tc := range tests {
53 t.Run(tc.name, func(t *testing.T) {
54 var out bytes.Buffer
55 fmtCtx := formatter.Context{
56 Format: tc.format,
57 Output: &out,
58 }
59 if err := stackWrite(fmtCtx, []stackSummary{
60 {Name: "baz", Services: 2},
61 {Name: "bar", Services: 1},
62 }); err != nil {
63 assert.Error(t, err, tc.expected)
64 } else {
65 assert.Equal(t, out.String(), tc.expected)
66 }
67 })
68 }

Callers

nothing calls this directly

Calls 3

stackWriteFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…