]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/go-getter/decompress_testing.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / decompress_testing.go
index 91cf33d98dfb0634b76163095ad4bac0c3c3484d..b2f662a89dfcb2fa7bb66b45b94e93ad2bc95498 100644 (file)
@@ -18,16 +18,18 @@ import (
 
 // 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)
 
@@ -72,9 +74,13 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
 
                                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())
                                        }
                                }
 
@@ -103,10 +109,15 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
                                                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())
                                        }
+
                                }
                        }
                }()