// TestDecompressCase is a single test case for testing decompressors
type TestDecompressCase struct {
- Input string // Input is the complete path to the input file
- Dir bool // Dir is whether or not we're testing directory mode
- Err bool // Err is whether we expect an error or not
- DirList []string // DirList is the list of files for Dir mode
- FileMD5 string // FileMD5 is the expected MD5 for a single file
- Mtime *time.Time // Mtime is the optionally expected mtime for a single file (or all files if in Dir mode)
+ Input string // Input is the complete path to the input file
+ Dir bool // Dir is whether or not we're testing directory mode
+ Err bool // Err is whether we expect an error or not
+ DirList []string // DirList is the list of files for Dir mode
+ FileMD5 string // FileMD5 is the expected MD5 for a single file
+ Mtime *time.Time // Mtime is the optionally expected mtime for a single file (or all files if in Dir mode)
}
// TestDecompressor is a helper function for testing generic decompressors.
func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
+ t.Helper()
+
for _, tc := range cases {
t.Logf("Testing: %s", tc.Input)
if tc.Mtime != nil {
actual := fi.ModTime()
- expected := *tc.Mtime
- if actual != expected {
- t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), dst, actual.String())
+ if tc.Mtime.Unix() > 0 {
+ expected := *tc.Mtime
+ if actual != expected {
+ t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), dst, actual.String())
+ }
+ } else if actual.Unix() <= 0 {
+ t.Fatalf("err %s: expected mtime to be > 0, got '%s'", actual.String())
}
}
t.Fatalf("err: %s", err)
}
actual := fi.ModTime()
- expected := *tc.Mtime
- if actual != expected {
- t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), path, actual.String())
+ if tc.Mtime.Unix() > 0 {
+ expected := *tc.Mtime
+ if actual != expected {
+ t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), path, actual.String())
+ }
+ } else if actual.Unix() < 0 {
+ t.Fatalf("err %s: expected mtime to be > 0, got '%s'", actual.String())
}
+
}
}
}()