MCPcopy Create free account
hub / github.com/cli/cli / createTarGzBuffer

Function createTarGzBuffer

pkg/cmd/copilot/copilot_test.go:171–191  ·  view source on GitHub ↗

createTarGzBuffer creates a tar.gz archive in memory with the given files.

(t *testing.T, files map[string][]byte)

Source from the content-addressed store, hash-verified

169
170// createTarGzBuffer creates a tar.gz archive in memory with the given files.
171func createTarGzBuffer(t *testing.T, files map[string][]byte) []byte {
172 t.Helper()
173 var buf bytes.Buffer
174 gw := gzip.NewWriter(&buf)
175 tw := tar.NewWriter(gw)
176
177 for name, content := range files {
178 hdr := &tar.Header{
179 Name: name,
180 Mode: 0755,
181 Size: int64(len(content)),
182 }
183 require.NoError(t, tw.WriteHeader(hdr), "failed to write tar header")
184 _, err := tw.Write(content)
185 require.NoError(t, err, "failed to write tar content")
186 }
187
188 require.NoError(t, tw.Close(), "failed to close tar writer")
189 require.NoError(t, gw.Close(), "failed to close gzip writer")
190 return buf.Bytes()
191}
192
193// createZipBuffer creates a zip archive in memory with the given files.
194func createZipBuffer(t *testing.T, files map[string][]byte) []byte {

Callers 2

TestExtractTarGzFunction · 0.85
TestDownloadCopilotFunction · 0.85

Calls 3

HelperMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected