(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestNewLoadCommandErrors(t *testing.T) { |
| 17 | testCases := []struct { |
| 18 | name string |
| 19 | args []string |
| 20 | isTerminalIn bool |
| 21 | expectedError string |
| 22 | imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) |
| 23 | }{ |
| 24 | { |
| 25 | name: "wrong-args", |
| 26 | args: []string{"arg"}, |
| 27 | expectedError: "accepts no arguments", |
| 28 | }, |
| 29 | { |
| 30 | name: "input-to-terminal", |
| 31 | args: []string{}, |
| 32 | isTerminalIn: true, |
| 33 | expectedError: "requested load from stdin, but stdin is empty", |
| 34 | }, |
| 35 | { |
| 36 | name: "pull-error", |
| 37 | args: []string{}, |
| 38 | expectedError: "something went wrong", |
| 39 | imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) { |
| 40 | return nil, errors.New("something went wrong") |
| 41 | }, |
| 42 | }, |
| 43 | { |
| 44 | name: "invalid platform", |
| 45 | args: []string{"--platform", "<invalid>"}, |
| 46 | expectedError: `invalid platform`, |
| 47 | imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) { |
| 48 | return io.NopCloser(strings.NewReader("")), nil |
| 49 | }, |
| 50 | }, |
| 51 | } |
| 52 | for _, tc := range testCases { |
| 53 | t.Run(tc.name, func(t *testing.T) { |
| 54 | cli := test.NewFakeCli(&fakeClient{imageLoadFunc: tc.imageLoadFunc}) |
| 55 | cli.In().SetIsTerminal(tc.isTerminalIn) |
| 56 | cmd := newLoadCommand(cli) |
| 57 | cmd.SetOut(io.Discard) |
| 58 | cmd.SetErr(io.Discard) |
| 59 | cmd.SetArgs(tc.args) |
| 60 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 61 | }) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func TestNewLoadCommandInvalidInput(t *testing.T) { |
| 66 | expectedError := "open *" |
nothing calls this directly
no test coverage detected
searching dependent graphs…