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

Function AssertSampleZipFile

archive/archivetest/archivetest.go:75–105  ·  view source on GitHub ↗

AssertSampleZipFile compares the content of zipBytes against testdata/test.zip.

(t *testing.T, zipBytes []byte)

Source from the content-addressed store, hash-verified

73
74// AssertSampleZipFile compares the content of zipBytes against testdata/test.zip.
75func 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.

Callers 3

TestDownloadFunction · 0.92
TestCreateTarFromZipFunction · 0.92
TestCreateZipFromTarFunction · 0.92

Calls 6

ArchiveRefTimeFunction · 0.85
HelperMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45
OpenMethod · 0.45
ReadAllMethod · 0.45

Tested by 3

TestDownloadFunction · 0.74
TestCreateTarFromZipFunction · 0.74
TestCreateZipFromTarFunction · 0.74