(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestNewPushCommandErrors(t *testing.T) { |
| 20 | testCases := []struct { |
| 21 | name string |
| 22 | args []string |
| 23 | expectedError string |
| 24 | imagePushFunc func(ref string, options client.ImagePushOptions) (client.ImagePushResponse, error) |
| 25 | }{ |
| 26 | { |
| 27 | name: "wrong-args", |
| 28 | args: []string{}, |
| 29 | expectedError: "requires 1 argument", |
| 30 | }, |
| 31 | { |
| 32 | name: "invalid-name", |
| 33 | args: []string{"UPPERCASE_REPO"}, |
| 34 | expectedError: "invalid reference format: repository name (library/UPPERCASE_REPO) must be lowercase", |
| 35 | }, |
| 36 | { |
| 37 | name: "push-failed", |
| 38 | args: []string{"image:repo"}, |
| 39 | expectedError: "failed to push", |
| 40 | imagePushFunc: func(ref string, options client.ImagePushOptions) (client.ImagePushResponse, error) { |
| 41 | return nil, errors.New("failed to push") |
| 42 | }, |
| 43 | }, |
| 44 | } |
| 45 | for _, tc := range testCases { |
| 46 | t.Run(tc.name, func(t *testing.T) { |
| 47 | cli := test.NewFakeCli(&fakeClient{imagePushFunc: tc.imagePushFunc}) |
| 48 | cmd := newPushCommand(cli) |
| 49 | cmd.SetOut(io.Discard) |
| 50 | cmd.SetErr(io.Discard) |
| 51 | cmd.SetArgs(tc.args) |
| 52 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestNewPushCommandSuccess(t *testing.T) { |
| 58 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…