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

Function TestImportZip

cli/context/store/store_test.go:166–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func TestImportZip(t *testing.T) {
167 testDir := t.TempDir()
168 zf := path.Join(testDir, "test.zip")
169
170 f, err := os.Create(zf)
171 assert.NilError(t, err)
172 defer f.Close()
173 w := zip.NewWriter(f)
174
175 meta, err := json.Marshal(Metadata{
176 Endpoints: map[string]any{
177 "ep1": endpoint{Foo: "bar"},
178 },
179 Metadata: context{Bar: "baz"},
180 Name: "source",
181 })
182 assert.NilError(t, err)
183 files := []struct {
184 Name, Body string
185 }{
186 {"meta.json", string(meta)},
187 {path.Join("tls", "docker", "ca.pem"), string([]byte("ca.pem"))},
188 }
189
190 for _, file := range files {
191 f, err := w.Create(file.Name)
192 assert.NilError(t, err)
193 _, err = f.Write([]byte(file.Body))
194 assert.NilError(t, err)
195 }
196
197 err = w.Close()
198 assert.NilError(t, err)
199
200 source, err := os.Open(zf)
201 assert.NilError(t, err)
202 ct, err := getImportContentType(bufio.NewReader(source))
203 assert.NilError(t, err)
204 assert.Equal(t, zipType, ct)
205
206 source, _ = os.Open(zf)
207 defer source.Close()
208 var r io.Reader = source
209 s := New(testDir, testCfg)
210 err = Import("zipTest", s, r)
211 assert.NilError(t, err)
212}
213
214func TestImportZipInvalid(t *testing.T) {
215 testDir := t.TempDir()

Callers

nothing calls this directly

Calls 5

getImportContentTypeFunction · 0.85
ImportFunction · 0.85
NewFunction · 0.70
CloseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…