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

Function AssertSampleTarFile

archive/archivetest/archivetest.go:33–72  ·  view source on GitHub ↗

AssertSampleTarfile compares the content of tarBytes against testdata/test.tar.

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

Source from the content-addressed store, hash-verified

31
32// AssertSampleTarfile compares the content of tarBytes against testdata/test.tar.
33func AssertSampleTarFile(t *testing.T, tarBytes []byte) {
34 t.Helper()
35
36 tr := tar.NewReader(bytes.NewReader(tarBytes))
37 for {
38 hdr, err := tr.Next()
39 if err != nil {
40 if err == io.EOF {
41 return
42 }
43 require.NoError(t, err)
44 }
45
46 // Note: ignoring timezones here.
47 require.Equal(t, ArchiveRefTime(t).UTC(), hdr.ModTime.UTC())
48
49 switch hdr.Name {
50 case "test/":
51 require.Equal(t, hdr.Typeflag, byte(tar.TypeDir))
52 case "test/hello.txt":
53 require.Equal(t, hdr.Typeflag, byte(tar.TypeReg))
54 bs, err := io.ReadAll(tr)
55 if err != nil && !xerrors.Is(err, io.EOF) {
56 require.NoError(t, err)
57 }
58 require.Equal(t, "hello", string(bs))
59 case "test/dir/":
60 require.Equal(t, hdr.Typeflag, byte(tar.TypeDir))
61 case "test/dir/world.txt":
62 require.Equal(t, hdr.Typeflag, byte(tar.TypeReg))
63 bs, err := io.ReadAll(tr)
64 if err != nil && !xerrors.Is(err, io.EOF) {
65 require.NoError(t, err)
66 }
67 require.Equal(t, "world", string(bs))
68 default:
69 require.Failf(t, "unexpected file in tar", hdr.Name)
70 }
71 }
72}
73
74// AssertSampleZipFile compares the content of zipBytes against testdata/test.zip.
75func AssertSampleZipFile(t *testing.T, zipBytes []byte) {

Callers 2

TestDownloadFunction · 0.92
TestCreateTarFromZipFunction · 0.92

Calls 6

ArchiveRefTimeFunction · 0.85
HelperMethod · 0.65
NextMethod · 0.65
EqualMethod · 0.45
ReadAllMethod · 0.45
IsMethod · 0.45

Tested by 2

TestDownloadFunction · 0.74
TestCreateTarFromZipFunction · 0.74