AssertSampleZipFile compares the content of zipBytes against testdata/test.zip.
(t *testing.T, zipBytes []byte)
| 73 | |
| 74 | // AssertSampleZipFile compares the content of zipBytes against testdata/test.zip. |
| 75 | func AssertSampleZipFile(t *testing.T, zipBytes []byte) { |
| 76 | t.Helper() |
| 77 | |
| 78 | zr, err := zip.NewReader(bytes.NewReader(zipBytes), int64(len(zipBytes))) |
| 79 | require.NoError(t, err) |
| 80 | |
| 81 | for _, f := range zr.File { |
| 82 | // Note: ignoring timezones here. |
| 83 | require.Equal(t, ArchiveRefTime(t).UTC(), f.Modified.UTC()) |
| 84 | switch f.Name { |
| 85 | case "test/", "test/dir/": |
| 86 | // directory |
| 87 | case "test/hello.txt": |
| 88 | rc, err := f.Open() |
| 89 | require.NoError(t, err) |
| 90 | bs, err := io.ReadAll(rc) |
| 91 | _ = rc.Close() |
| 92 | require.NoError(t, err) |
| 93 | require.Equal(t, "hello", string(bs)) |
| 94 | case "test/dir/world.txt": |
| 95 | rc, err := f.Open() |
| 96 | require.NoError(t, err) |
| 97 | bs, err := io.ReadAll(rc) |
| 98 | _ = rc.Close() |
| 99 | require.NoError(t, err) |
| 100 | require.Equal(t, "world", string(bs)) |
| 101 | default: |
| 102 | require.Failf(t, "unexpected file in zip", f.Name) |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // archiveRefTime is the Go reference time. The contents of the sample tar and zip files |
| 108 | // in testdata/ all have their modtimes set to the below in some timezone. |