(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestNewHistoryCommandErrors(t *testing.T) { |
| 18 | testCases := []struct { |
| 19 | name string |
| 20 | args []string |
| 21 | expectedError string |
| 22 | imageHistoryFunc func(img string, options ...client.ImageHistoryOption) (client.ImageHistoryResult, error) |
| 23 | }{ |
| 24 | { |
| 25 | name: "wrong-args", |
| 26 | args: []string{}, |
| 27 | expectedError: "requires 1 argument", |
| 28 | }, |
| 29 | { |
| 30 | name: "client-error", |
| 31 | args: []string{"image:tag"}, |
| 32 | expectedError: "something went wrong", |
| 33 | imageHistoryFunc: func(string, ...client.ImageHistoryOption) (client.ImageHistoryResult, error) { |
| 34 | return client.ImageHistoryResult{}, errors.New("something went wrong") |
| 35 | }, |
| 36 | }, |
| 37 | { |
| 38 | name: "invalid platform", |
| 39 | args: []string{"--platform", "<invalid>", "arg1"}, |
| 40 | expectedError: `invalid platform`, |
| 41 | }, |
| 42 | } |
| 43 | for _, tc := range testCases { |
| 44 | t.Run(tc.name, func(t *testing.T) { |
| 45 | cmd := newHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})) |
| 46 | cmd.SetOut(io.Discard) |
| 47 | cmd.SetErr(io.Discard) |
| 48 | cmd.SetArgs(tc.args) |
| 49 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 50 | }) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func TestNewHistoryCommandSuccess(t *testing.T) { |
| 55 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…