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

Function TestDiffContextFormatWrite

cli/command/container/formatter_diff_test.go:13–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestDiffContextFormatWrite(t *testing.T) {
14 // Check default output format (verbose and non-verbose mode) for table headers
15 cases := []struct {
16 context formatter.Context
17 expected string
18 }{
19 {
20 formatter.Context{Format: newDiffFormat("table")},
21 `CHANGE TYPE PATH
22C /var/log/app.log
23A /usr/app/app.js
24D /usr/app/old_app.js
25`,
26 },
27 {
28 formatter.Context{Format: newDiffFormat("table {{.Path}}")},
29 `PATH
30/var/log/app.log
31/usr/app/app.js
32/usr/app/old_app.js
33`,
34 },
35 {
36 formatter.Context{Format: newDiffFormat("{{.Type}}: {{.Path}}")},
37 `C: /var/log/app.log
38A: /usr/app/app.js
39D: /usr/app/old_app.js
40`,
41 },
42 }
43
44 diffs := client.ContainerDiffResult{
45 Changes: []container.FilesystemChange{
46 {Kind: container.ChangeModify, Path: "/var/log/app.log"},
47 {Kind: container.ChangeAdd, Path: "/usr/app/app.js"},
48 {Kind: container.ChangeDelete, Path: "/usr/app/old_app.js"},
49 },
50 }
51
52 for _, tc := range cases {
53 t.Run(string(tc.context.Format), func(t *testing.T) {
54 out := bytes.NewBufferString("")
55 tc.context.Output = out
56 err := diffFormatWrite(tc.context, diffs)
57 if err != nil {
58 assert.Error(t, err, tc.expected)
59 } else {
60 assert.Equal(t, out.String(), tc.expected)
61 }
62 })
63 }
64}

Callers

nothing calls this directly

Calls 4

newDiffFormatFunction · 0.85
diffFormatWriteFunction · 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…