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

Function TestNewSaveCommandSuccess

cli/command/image/save_test.go:73–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestNewSaveCommandSuccess(t *testing.T) {
74 testCases := []struct {
75 args []string
76 isTerminal bool
77 imageSaveFunc func(images []string, options ...client.ImageSaveOption) (client.ImageSaveResult, error)
78 deferredFunc func()
79 }{
80 {
81 args: []string{"-o", "save_tmp_file", "arg1"},
82 isTerminal: true,
83 imageSaveFunc: func(images []string, options ...client.ImageSaveOption) (client.ImageSaveResult, error) {
84 assert.Assert(t, is.Len(images, 1))
85 assert.Check(t, is.Equal("arg1", images[0]))
86 return io.NopCloser(strings.NewReader("")), nil
87 },
88 deferredFunc: func() {
89 _ = os.Remove("save_tmp_file")
90 },
91 },
92 {
93 args: []string{"arg1", "arg2"},
94 isTerminal: false,
95 imageSaveFunc: func(images []string, options ...client.ImageSaveOption) (client.ImageSaveResult, error) {
96 assert.Assert(t, is.Len(images, 2))
97 assert.Check(t, is.Equal("arg1", images[0]))
98 assert.Check(t, is.Equal("arg2", images[1]))
99 return io.NopCloser(strings.NewReader("")), nil
100 },
101 },
102 {
103 args: []string{"--platform", "linux/amd64", "arg1"},
104 isTerminal: false,
105 imageSaveFunc: func(images []string, options ...client.ImageSaveOption) (client.ImageSaveResult, error) {
106 assert.Assert(t, is.Len(images, 1))
107 assert.Check(t, is.Equal("arg1", images[0]))
108 // FIXME(thaJeztah): need to find appropriate way to test the result of "ImageHistoryWithPlatform" being applied
109 assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
110 // assert.Check(t, is.Contains(options, client.ImageHistoryWithPlatform(ocispec.Platform{OS: "linux", Architecture: "amd64"})))
111 return io.NopCloser(strings.NewReader("")), nil
112 },
113 },
114 {
115 args: []string{"--platform", "linux/amd64,linux/arm64/v8,linux/riscv64", "arg1"},
116 isTerminal: false,
117 imageSaveFunc: func(images []string, options ...client.ImageSaveOption) (client.ImageSaveResult, error) {
118 assert.Assert(t, is.Len(images, 1))
119 assert.Check(t, is.Equal("arg1", images[0]))
120 assert.Check(t, len(options) > 0) // can be 1 or 2 depending on whether a terminal is attached :/
121 return io.NopCloser(strings.NewReader("")), nil
122 },
123 },
124 {
125 args: []string{"--platform", "linux/amd64", "--platform", "linux/arm64/v8", "--platform", "linux/riscv64", "arg1"},
126 isTerminal: false,
127 imageSaveFunc: func(images []string, options ...client.ImageSaveOption) (client.ImageSaveResult, error) {
128 assert.Assert(t, is.Len(images, 1))
129 assert.Check(t, is.Equal("arg1", images[0]))
130 assert.Check(t, len(options) > 0) // can be 1 or 2 depending on whether a terminal is attached :/

Callers

nothing calls this directly

Calls 6

newSaveCommandFunction · 0.85
SetArgsMethod · 0.80
RemoveMethod · 0.65
LenMethod · 0.45
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…