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

Function TestRunDiff

cli/command/container/diff_test.go:17–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestRunDiff(t *testing.T) {
18 cli := test.NewFakeCli(&fakeClient{
19 containerDiffFunc: func(ctx context.Context, containerID string) (client.ContainerDiffResult, error) {
20 return client.ContainerDiffResult{
21 Changes: []container.FilesystemChange{
22 {
23 Kind: container.ChangeModify,
24 Path: "/path/to/file0",
25 },
26 {
27 Kind: container.ChangeAdd,
28 Path: "/path/to/file1",
29 },
30 {
31 Kind: container.ChangeDelete,
32 Path: "/path/to/file2",
33 },
34 },
35 }, nil
36 },
37 })
38
39 cmd := newDiffCommand(cli)
40 cmd.SetOut(io.Discard)
41
42 cmd.SetArgs([]string{"container-id"})
43
44 err := cmd.Execute()
45 assert.NilError(t, err)
46
47 diff := strings.SplitN(cli.OutBuffer().String(), "\n", 3)
48 assert.Assert(t, is.Len(diff, 3))
49
50 file0 := strings.TrimSpace(diff[0])
51 file1 := strings.TrimSpace(diff[1])
52 file2 := strings.TrimSpace(diff[2])
53
54 assert.Check(t, is.Equal(file0, "C /path/to/file0"))
55 assert.Check(t, is.Equal(file1, "A /path/to/file1"))
56 assert.Check(t, is.Equal(file2, "D /path/to/file2"))
57}
58
59func TestRunDiffClientError(t *testing.T) {
60 clientError := errors.New("client error")

Callers

nothing calls this directly

Calls 6

OutBufferMethod · 0.95
newDiffCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65
SetOutMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…