aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-getter/decompress_testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/decompress_testing.go')
-rw-r--r--vendor/github.com/hashicorp/go-getter/decompress_testing.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/decompress_testing.go b/vendor/github.com/hashicorp/go-getter/decompress_testing.go
index 686d6c2..91cf33d 100644
--- a/vendor/github.com/hashicorp/go-getter/decompress_testing.go
+++ b/vendor/github.com/hashicorp/go-getter/decompress_testing.go
@@ -11,7 +11,9 @@ import (
11 "runtime" 11 "runtime"
12 "sort" 12 "sort"
13 "strings" 13 "strings"
14 "testing" 14 "time"
15
16 "github.com/mitchellh/go-testing-interface"
15) 17)
16 18
17// TestDecompressCase is a single test case for testing decompressors 19// TestDecompressCase is a single test case for testing decompressors
@@ -21,10 +23,11 @@ type TestDecompressCase struct {
21 Err bool // Err is whether we expect an error or not 23 Err bool // Err is whether we expect an error or not
22 DirList []string // DirList is the list of files for Dir mode 24 DirList []string // DirList is the list of files for Dir mode
23 FileMD5 string // FileMD5 is the expected MD5 for a single file 25 FileMD5 string // FileMD5 is the expected MD5 for a single file
26 Mtime *time.Time // Mtime is the optionally expected mtime for a single file (or all files if in Dir mode)
24} 27}
25 28
26// TestDecompressor is a helper function for testing generic decompressors. 29// TestDecompressor is a helper function for testing generic decompressors.
27func TestDecompressor(t *testing.T, d Decompressor, cases []TestDecompressCase) { 30func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
28 for _, tc := range cases { 31 for _, tc := range cases {
29 t.Logf("Testing: %s", tc.Input) 32 t.Logf("Testing: %s", tc.Input)
30 33
@@ -67,6 +70,14 @@ func TestDecompressor(t *testing.T, d Decompressor, cases []TestDecompressCase)
67 } 70 }
68 } 71 }
69 72
73 if tc.Mtime != nil {
74 actual := fi.ModTime()
75 expected := *tc.Mtime
76 if actual != expected {
77 t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), dst, actual.String())
78 }
79 }
80
70 return 81 return
71 } 82 }
72 83
@@ -83,11 +94,26 @@ func TestDecompressor(t *testing.T, d Decompressor, cases []TestDecompressCase)
83 if !reflect.DeepEqual(actual, expected) { 94 if !reflect.DeepEqual(actual, expected) {
84 t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual, expected) 95 t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual, expected)
85 } 96 }
97 // Check for correct atime/mtime
98 for _, dir := range actual {
99 path := filepath.Join(dst, dir)
100 if tc.Mtime != nil {
101 fi, err := os.Stat(path)
102 if err != nil {
103 t.Fatalf("err: %s", err)
104 }
105 actual := fi.ModTime()
106 expected := *tc.Mtime
107 if actual != expected {
108 t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), path, actual.String())
109 }
110 }
111 }
86 }() 112 }()
87 } 113 }
88} 114}
89 115
90func testListDir(t *testing.T, path string) []string { 116func testListDir(t testing.T, path string) []string {
91 var result []string 117 var result []string
92 err := filepath.Walk(path, func(sub string, info os.FileInfo, err error) error { 118 err := filepath.Walk(path, func(sub string, info os.FileInfo, err error) error {
93 if err != nil { 119 if err != nil {
@@ -102,7 +128,7 @@ func testListDir(t *testing.T, path string) []string {
102 128
103 // If it is a dir, add trailing sep 129 // If it is a dir, add trailing sep
104 if info.IsDir() { 130 if info.IsDir() {
105 sub += "/" 131 sub += string(os.PathSeparator)
106 } 132 }
107 133
108 result = append(result, sub) 134 result = append(result, sub)
@@ -116,7 +142,7 @@ func testListDir(t *testing.T, path string) []string {
116 return result 142 return result
117} 143}
118 144
119func testMD5(t *testing.T, path string) string { 145func testMD5(t testing.T, path string) string {
120 f, err := os.Open(path) 146 f, err := os.Open(path)
121 if err != nil { 147 if err != nil {
122 t.Fatalf("err: %s", err) 148 t.Fatalf("err: %s", err)