| 55 | } |
| 56 | |
| 57 | func TestNewPushCommandSuccess(t *testing.T) { |
| 58 | testCases := []struct { |
| 59 | name string |
| 60 | args []string |
| 61 | output string |
| 62 | }{ |
| 63 | { |
| 64 | name: "push", |
| 65 | args: []string{"image:tag"}, |
| 66 | }, |
| 67 | { |
| 68 | name: "push quiet", |
| 69 | args: []string{"--quiet", "image:tag"}, |
| 70 | output: `docker.io/library/image:tag |
| 71 | `, |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | for _, tc := range testCases { |
| 76 | t.Run(tc.name, func(t *testing.T) { |
| 77 | cli := test.NewFakeCli(&fakeClient{ |
| 78 | imagePushFunc: func(ref string, options client.ImagePushOptions) (client.ImagePushResponse, error) { |
| 79 | // FIXME(thaJeztah): how to mock this? |
| 80 | return fakeStreamResult{ReadCloser: http.NoBody}, nil |
| 81 | }, |
| 82 | }) |
| 83 | cmd := newPushCommand(cli) |
| 84 | cmd.SetOut(cli.OutBuffer()) |
| 85 | cmd.SetErr(io.Discard) |
| 86 | cmd.SetArgs(tc.args) |
| 87 | assert.NilError(t, cmd.Execute()) |
| 88 | if tc.output != "" { |
| 89 | assert.Equal(t, tc.output, cli.OutBuffer().String()) |
| 90 | } |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func TestRunPushRespectsNoColorForAuxNotes(t *testing.T) { |
| 96 | t.Setenv("NO_COLOR", "1") |