| 15 | ) |
| 16 | |
| 17 | func 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 | |
| 59 | func TestRunDiffClientError(t *testing.T) { |
| 60 | clientError := errors.New("client error") |