MCPcopy Index your code
hub / github.com/docker/docker-agent / TestExtractZip

Function TestExtractZip

pkg/toolinstall/archive_test.go:125–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

123}
124
125func TestExtractZip(t *testing.T) {
126 t.Parallel()
127
128 var buf bytes.Buffer
129 zw := zip.NewWriter(&buf)
130
131 content := []byte("#!/bin/sh\necho hello")
132 fw, err := zw.Create("tool_1.0.0/bin/mytool")
133 require.NoError(t, err)
134 _, err = fw.Write(content)
135 require.NoError(t, err)
136 require.NoError(t, zw.Close())
137
138 destDir := t.TempDir()
139 files := []PackageFile{{Name: "mytool", Src: "tool_{{.Version}}/bin/mytool"}}
140 data := templateData{Version: "1.0.0", OS: "linux", Arch: "amd64"}
141
142 require.NoError(t, defaultLimits().extractZip(bytes.NewReader(buf.Bytes()), int64(buf.Len()), destDir, files, data))
143
144 extracted, err := os.ReadFile(filepath.Join(destDir, "mytool"))
145 require.NoError(t, err)
146 assert.Equal(t, content, extracted)
147}
148
149func TestBuildFileMap(t *testing.T) {
150 t.Parallel()

Callers

nothing calls this directly

Calls 7

BytesMethod · 0.95
LenMethod · 0.95
defaultLimitsFunction · 0.85
extractZipMethod · 0.80
ReadFileMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected