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

Function TestNewLoadCommandSuccess

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

Source from the content-addressed store, hash-verified

77}
78
79func TestNewLoadCommandSuccess(t *testing.T) {
80 testCases := []struct {
81 name string
82 args []string
83 imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error)
84 }{
85 {
86 name: "simple",
87 args: []string{},
88 imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
89 // FIXME(thaJeztah): how to mock this?
90 // return client.ImageLoadResult{
91 // Body: io.NopCloser(strings.NewReader(`{"ID":"simple","Status":"success"}`)),
92 // }, nil
93 return mockImageLoadResult(`{"ID":"simple","Status":"success"}`), nil
94 },
95 },
96 {
97 name: "input-file",
98 args: []string{"--input", "testdata/load-command-success.input.txt"},
99 imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
100 // FIXME(thaJeztah): how to mock this?
101 // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"input-file","Status":"success"}`))}, nil
102 return mockImageLoadResult(`{"ID":"input-file","Status":"success"}`), nil
103 },
104 },
105 {
106 name: "with-single-platform",
107 args: []string{"--platform", "linux/amd64"},
108 imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
109 // FIXME(thaJeztah): need to find appropriate way to test the result of "ImageHistoryWithPlatform" being applied
110 assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
111 // assert.Check(t, is.Contains(options, client.ImageHistoryWithPlatform(ocispec.Platform{OS: "linux", Architecture: "amd64"})))
112 // FIXME(thaJeztah): how to mock this?
113 // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"single-platform","Status":"success"}`))}, nil
114 return mockImageLoadResult(`{"ID":"single-platform","Status":"success"}`), nil
115 },
116 },
117 {
118 name: "with-comma-separated-platforms",
119 args: []string{"--platform", "linux/amd64,linux/arm64/v8,linux/riscv64"},
120 imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
121 assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
122 // FIXME(thaJeztah): how to mock this?
123 // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"with-comma-separated-platforms","Status":"success"}`))}, nil
124 return mockImageLoadResult(`{"ID":"with-comma-separated-platforms","Status":"success"}`), nil
125 },
126 },
127 {
128 name: "with-multiple-platform-options",
129 args: []string{"--platform", "linux/amd64", "--platform", "linux/arm64/v8", "--platform", "linux/riscv64"},
130 imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (client.ImageLoadResult, error) {
131 assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
132 // FIXME(thaJeztah): how to mock this?
133 // return client.ImageLoadResult{Body: io.NopCloser(strings.NewReader(`{"ID":"with-multiple-platform-options","Status":"success"}`))}, nil
134 return mockImageLoadResult(`{"ID":"with-multiple-platform-options","Status":"success"}`), nil
135 },
136 },

Callers

nothing calls this directly

Calls 6

OutBufferMethod · 0.95
mockImageLoadResultFunction · 0.85
newLoadCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65
SetOutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…