MCPcopy Index your code
hub / github.com/docker/cli / TestNewPushCommandErrors

Function TestNewPushCommandErrors

cli/command/image/push_test.go:19–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func 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
57func TestNewPushCommandSuccess(t *testing.T) {
58 testCases := []struct {

Callers

nothing calls this directly

Calls 4

SetArgsMethod · 0.80
newPushCommandFunction · 0.70
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…