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

Function TestNewImportCommandSuccess

cli/command/image/import_test.go:53–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestNewImportCommandSuccess(t *testing.T) {
54 testCases := []struct {
55 name string
56 args []string
57 imageImportFunc func(source client.ImageImportSource, ref string, options client.ImageImportOptions) (client.ImageImportResult, error)
58 }{
59 {
60 name: "simple",
61 args: []string{"testdata/import-command-success.input.txt"},
62 },
63 {
64 name: "terminal-source",
65 args: []string{"-"},
66 },
67 {
68 name: "double",
69 args: []string{"-", "image:local"},
70 imageImportFunc: func(source client.ImageImportSource, ref string, options client.ImageImportOptions) (client.ImageImportResult, error) {
71 assert.Check(t, is.Equal("image:local", ref))
72 return io.NopCloser(strings.NewReader("")), nil
73 },
74 },
75 {
76 name: "message",
77 args: []string{"--message", "test message", "-"},
78 imageImportFunc: func(source client.ImageImportSource, ref string, options client.ImageImportOptions) (client.ImageImportResult, error) {
79 assert.Check(t, is.Equal("test message", options.Message))
80 return io.NopCloser(strings.NewReader("")), nil
81 },
82 },
83 {
84 name: "change",
85 args: []string{"--change", "ENV DEBUG=true", "-"},
86 imageImportFunc: func(source client.ImageImportSource, ref string, options client.ImageImportOptions) (client.ImageImportResult, error) {
87 assert.Check(t, is.Equal("ENV DEBUG=true", options.Changes[0]))
88 return io.NopCloser(strings.NewReader("")), nil
89 },
90 },
91 {
92 name: "change legacy syntax",
93 args: []string{"--change", "ENV DEBUG true", "-"},
94 imageImportFunc: func(source client.ImageImportSource, ref string, options client.ImageImportOptions) (client.ImageImportResult, error) {
95 assert.Check(t, is.Equal("ENV DEBUG true", options.Changes[0]))
96 return io.NopCloser(strings.NewReader("")), nil
97 },
98 },
99 }
100 for _, tc := range testCases {
101 t.Run(tc.name, func(t *testing.T) {
102 cmd := newImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
103 cmd.SetOut(io.Discard)
104 cmd.SetErr(io.Discard)
105 cmd.SetArgs(tc.args)
106 assert.NilError(t, cmd.Execute())
107 })
108 }
109}

Callers

nothing calls this directly

Calls 4

SetArgsMethod · 0.80
newImportCommandFunction · 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…