Skip to content

Commit

Permalink
test: add modifed time test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien HOUZÉ committed Jul 21, 2021
1 parent 1218f58 commit 273acc9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Binary file modified internal/provider/archive-dir.zip
Binary file not shown.
Binary file modified internal/provider/archive-file.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions internal/provider/zip_archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func TestZipArchiver_FileModified(t *testing.T) {
if !bytes.Equal(expectedContents, actualContents) {
t.Fatalf("zip contents do not match, potentially a modified time issue")
}

oldestZipSupportedModTime, _ := time.Parse(time.RFC3339, "1980-01-01T00:00:00+00:00")
ensureModifiedtimes(t, zipFilePath, oldestZipSupportedModTime)
}

func TestZipArchiver_Dir(t *testing.T) {
Expand Down Expand Up @@ -153,6 +156,20 @@ func TestZipArchiver_Multiple(t *testing.T) {
ensureContents(t, zipfilepath, content)
}

func ensureModifiedtimes(t *testing.T, zipfilepath string, modifiedTime time.Time) {
r, err := zip.OpenReader(zipfilepath)
if err != nil {
t.Fatalf("could not open zip file: %s", err)
}
defer r.Close()

for _, cf := range r.File {
if !cf.Modified.Equal(modifiedTime) {
t.Fatalf("Modified time does not match, got %s, want %s", cf.Modified, modifiedTime)
}
}
}

func ensureContents(t *testing.T, zipfilepath string, wants map[string][]byte) {
t.Helper()
r, err := zip.OpenReader(zipfilepath)
Expand Down

0 comments on commit 273acc9

Please sign in to comment.