MCPcopy Index your code
hub / github.com/coder/coder / TestCreateTarFromZip

Function TestCreateTarFromZip

archive/archive_test.go:24–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestCreateTarFromZip(t *testing.T) {
25 t.Parallel()
26 if runtime.GOOS != "linux" {
27 t.Skip("skipping this test on non-Linux platform")
28 }
29
30 // Read a zip file we prepared earlier
31 ctx := testutil.Context(t, testutil.WaitShort)
32 zipBytes := archivetest.TestZipFileBytes()
33 // Assert invariant
34 archivetest.AssertSampleZipFile(t, zipBytes)
35
36 zr, err := zip.NewReader(bytes.NewReader(zipBytes), int64(len(zipBytes)))
37 require.NoError(t, err, "failed to parse sample zip file")
38
39 wantTar := archivetest.TestTarFileBytes()
40 gotTar, err := archive.CreateTarFromZip(zr, int64(len(wantTar)))
41 require.NoError(t, err, "failed to convert zip to tar")
42
43 archivetest.AssertSampleTarFile(t, gotTar)
44
45 tempDir := t.TempDir()
46 tempFilePath := filepath.Join(tempDir, "test.tar")
47 err = os.WriteFile(tempFilePath, gotTar, 0o600)
48 require.NoError(t, err, "failed to write converted tar file")
49
50 cmd := exec.CommandContext(ctx, "tar", "--extract", "--verbose", "--file", tempFilePath, "--directory", tempDir)
51 require.NoError(t, cmd.Run(), "failed to extract converted tar file")
52 assertExtractedFiles(t, tempDir, true)
53}
54
55func buildTestZip(t *testing.T, files map[string]string) []byte {
56 t.Helper()

Callers

nothing calls this directly

Calls 12

ContextFunction · 0.92
TestZipFileBytesFunction · 0.92
AssertSampleZipFileFunction · 0.92
TestTarFileBytesFunction · 0.92
CreateTarFromZipFunction · 0.92
AssertSampleTarFileFunction · 0.92
assertExtractedFilesFunction · 0.85
SkipMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
CommandContextMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected