(t *testing.T)
| 37 | } |
| 38 | |
| 39 | func TestNewInspectCommandSuccess(t *testing.T) { |
| 40 | imageInspectInvocationCount := 0 |
| 41 | testCases := []struct { |
| 42 | name string |
| 43 | args []string |
| 44 | imageCount int |
| 45 | imageInspectFunc func(img string) (client.ImageInspectResult, error) |
| 46 | }{ |
| 47 | { |
| 48 | name: "simple", |
| 49 | args: []string{"image"}, |
| 50 | imageCount: 1, |
| 51 | imageInspectFunc: func(img string) (client.ImageInspectResult, error) { |
| 52 | imageInspectInvocationCount++ |
| 53 | assert.Check(t, is.Equal("image", img)) |
| 54 | return client.ImageInspectResult{}, nil |
| 55 | }, |
| 56 | }, |
| 57 | { |
| 58 | name: "format", |
| 59 | imageCount: 1, |
| 60 | args: []string{"--format='{{.ID}}'", "image"}, |
| 61 | imageInspectFunc: func(img string) (client.ImageInspectResult, error) { |
| 62 | imageInspectInvocationCount++ |
| 63 | return client.ImageInspectResult{ |
| 64 | InspectResponse: image.InspectResponse{ID: img}, |
| 65 | }, nil |
| 66 | }, |
| 67 | }, |
| 68 | { |
| 69 | name: "simple-many", |
| 70 | args: []string{"image1", "image2"}, |
| 71 | imageCount: 2, |
| 72 | imageInspectFunc: func(img string) (client.ImageInspectResult, error) { |
| 73 | imageInspectInvocationCount++ |
| 74 | if imageInspectInvocationCount == 1 { |
| 75 | assert.Check(t, is.Equal("image1", img)) |
| 76 | } else { |
| 77 | assert.Check(t, is.Equal("image2", img)) |
| 78 | } |
| 79 | return client.ImageInspectResult{}, nil |
| 80 | }, |
| 81 | }, |
| 82 | } |
| 83 | for _, tc := range testCases { |
| 84 | t.Run(tc.name, func(t *testing.T) { |
| 85 | imageInspectInvocationCount = 0 |
| 86 | cli := test.NewFakeCli(&fakeClient{imageInspectFunc: tc.imageInspectFunc}) |
| 87 | cmd := newInspectCommand(cli) |
| 88 | cmd.SetOut(io.Discard) |
| 89 | cmd.SetArgs(tc.args) |
| 90 | err := cmd.Execute() |
| 91 | assert.NilError(t, err) |
| 92 | golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name)) |
| 93 | assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount)) |
| 94 | }) |
| 95 | } |
| 96 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…