(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func 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 | |
| 55 | func buildTestZip(t *testing.T, files map[string]string) []byte { |
| 56 | t.Helper() |
nothing calls this directly
no test coverage detected