|
0 |
Index: golang-github-hashicorp-go-slug/slug_test.go
|
|
1 |
===================================================================
|
|
2 |
--- golang-github-hashicorp-go-slug.orig/slug_test.go 2023-02-05 11:43:28.699878054 +0100
|
|
3 |
+++ golang-github-hashicorp-go-slug/slug_test.go 2023-02-05 11:46:12.815921418 +0100
|
|
4 |
@@ -15,203 +15,6 @@
|
|
5 |
"testing"
|
|
6 |
)
|
|
7 |
|
|
8 |
-func TestPack(t *testing.T) {
|
|
9 |
- slug := bytes.NewBuffer(nil)
|
|
10 |
-
|
|
11 |
- meta, err := Pack("testdata/archive-dir", slug, true)
|
|
12 |
- if err != nil {
|
|
13 |
- t.Fatalf("err: %v", err)
|
|
14 |
- }
|
|
15 |
-
|
|
16 |
- gzipR, err := gzip.NewReader(slug)
|
|
17 |
- if err != nil {
|
|
18 |
- t.Fatalf("err: %v", err)
|
|
19 |
- }
|
|
20 |
-
|
|
21 |
- tarR := tar.NewReader(gzipR)
|
|
22 |
- var (
|
|
23 |
- symFound bool
|
|
24 |
- fileList []string
|
|
25 |
- slugSize int64
|
|
26 |
- )
|
|
27 |
-
|
|
28 |
- for {
|
|
29 |
- hdr, err := tarR.Next()
|
|
30 |
- if err == io.EOF {
|
|
31 |
- break
|
|
32 |
- }
|
|
33 |
- if err != nil {
|
|
34 |
- t.Fatalf("err: %v", err)
|
|
35 |
- }
|
|
36 |
-
|
|
37 |
- fileList = append(fileList, hdr.Name)
|
|
38 |
- if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA {
|
|
39 |
- slugSize += hdr.Size
|
|
40 |
- }
|
|
41 |
-
|
|
42 |
- if hdr.Name == "sub/bar.txt" {
|
|
43 |
- if hdr.Typeflag != tar.TypeSymlink {
|
|
44 |
- t.Fatalf("expect symlink for file 'sub/bar.txt'")
|
|
45 |
- }
|
|
46 |
- if hdr.Linkname != "../bar.txt" {
|
|
47 |
- t.Fatalf("expect target of '../bar.txt', got %q", hdr.Linkname)
|
|
48 |
- }
|
|
49 |
- symFound = true
|
|
50 |
- }
|
|
51 |
- }
|
|
52 |
-
|
|
53 |
- // Make sure we saw and handled a symlink
|
|
54 |
- if !symFound {
|
|
55 |
- t.Fatal("expected to find symlink")
|
|
56 |
- }
|
|
57 |
-
|
|
58 |
- // Make sure the .git directory is ignored
|
|
59 |
- for _, file := range fileList {
|
|
60 |
- if strings.Contains(file, ".git") {
|
|
61 |
- t.Fatalf("unexpected .git content: %s", file)
|
|
62 |
- }
|
|
63 |
- }
|
|
64 |
-
|
|
65 |
- // Make sure the .terraform directory is ignored,
|
|
66 |
- // except for the .terraform/modules subdirectory.
|
|
67 |
- for _, file := range fileList {
|
|
68 |
- if strings.HasPrefix(file, ".terraform"+string(filepath.Separator)) &&
|
|
69 |
- !strings.HasPrefix(file, filepath.Clean(".terraform/modules")) {
|
|
70 |
- t.Fatalf("unexpected .terraform content: %s", file)
|
|
71 |
- }
|
|
72 |
- }
|
|
73 |
-
|
|
74 |
- // Make sure .terraform/modules is included.
|
|
75 |
- moduleDir := false
|
|
76 |
- for _, file := range fileList {
|
|
77 |
- if strings.HasPrefix(file, filepath.Clean(".terraform/modules")) {
|
|
78 |
- moduleDir = true
|
|
79 |
- break
|
|
80 |
- }
|
|
81 |
- }
|
|
82 |
- if !moduleDir {
|
|
83 |
- t.Fatal("expected to include .terraform/modules")
|
|
84 |
- }
|
|
85 |
-
|
|
86 |
- // Make sure .terraformrc is included.
|
|
87 |
- terraformrc := false
|
|
88 |
- for _, file := range fileList {
|
|
89 |
- if file == ".terraformrc" {
|
|
90 |
- terraformrc = true
|
|
91 |
- break
|
|
92 |
- }
|
|
93 |
- }
|
|
94 |
- if !terraformrc {
|
|
95 |
- t.Fatal("expected to include .terraformrc")
|
|
96 |
- }
|
|
97 |
-
|
|
98 |
- // Make sure foo.terraform/bar.txt is included.
|
|
99 |
- fooTerraformDir := false
|
|
100 |
- for _, file := range fileList {
|
|
101 |
- if file == filepath.Clean("foo.terraform/bar.txt") {
|
|
102 |
- fooTerraformDir = true
|
|
103 |
- break
|
|
104 |
- }
|
|
105 |
- }
|
|
106 |
- if !fooTerraformDir {
|
|
107 |
- t.Fatal("expected to include foo.terraform/bar.txt")
|
|
108 |
- }
|
|
109 |
-
|
|
110 |
- // Make sure baz.txt is excluded.
|
|
111 |
- bazTxt := false
|
|
112 |
- for _, file := range fileList {
|
|
113 |
- if file == filepath.Clean("baz.txt") {
|
|
114 |
- bazTxt = true
|
|
115 |
- break
|
|
116 |
- }
|
|
117 |
- }
|
|
118 |
- if bazTxt {
|
|
119 |
- t.Fatal("should not include baz.txt")
|
|
120 |
- }
|
|
121 |
-
|
|
122 |
- // Check the metadata
|
|
123 |
- expect := &Meta{
|
|
124 |
- Files: fileList,
|
|
125 |
- Size: slugSize,
|
|
126 |
- }
|
|
127 |
- if !reflect.DeepEqual(meta, expect) {
|
|
128 |
- t.Fatalf("\nexpect:\n%#v\n\nactual:\n%#v", expect, meta)
|
|
129 |
- }
|
|
130 |
-}
|
|
131 |
-
|
|
132 |
-func TestPackWithoutIgnoring(t *testing.T) {
|
|
133 |
- slug := bytes.NewBuffer(nil)
|
|
134 |
-
|
|
135 |
- // By default NewPacker() creates a Packer that does not use
|
|
136 |
- // .terraformignore or dereference symlinks.
|
|
137 |
- p, err := NewPacker()
|
|
138 |
- if err != nil {
|
|
139 |
- t.Fatalf("err: %v", err)
|
|
140 |
- }
|
|
141 |
-
|
|
142 |
- meta, err := p.Pack("testdata/archive-dir", slug)
|
|
143 |
- if err != nil {
|
|
144 |
- t.Fatalf("err: %v", err)
|
|
145 |
- }
|
|
146 |
-
|
|
147 |
- gzipR, err := gzip.NewReader(slug)
|
|
148 |
- if err != nil {
|
|
149 |
- t.Fatalf("err: %v", err)
|
|
150 |
- }
|
|
151 |
-
|
|
152 |
- tarR := tar.NewReader(gzipR)
|
|
153 |
- var (
|
|
154 |
- fileList []string
|
|
155 |
- slugSize int64
|
|
156 |
- )
|
|
157 |
-
|
|
158 |
- for {
|
|
159 |
- hdr, err := tarR.Next()
|
|
160 |
- if err == io.EOF {
|
|
161 |
- break
|
|
162 |
- }
|
|
163 |
- if err != nil {
|
|
164 |
- t.Fatalf("err: %v", err)
|
|
165 |
- }
|
|
166 |
-
|
|
167 |
- fileList = append(fileList, hdr.Name)
|
|
168 |
- if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA {
|
|
169 |
- slugSize += hdr.Size
|
|
170 |
- }
|
|
171 |
- }
|
|
172 |
-
|
|
173 |
- // baz.txt would normally be ignored, but should not be
|
|
174 |
- var bazFound bool
|
|
175 |
- for _, file := range fileList {
|
|
176 |
- if file == "baz.txt" {
|
|
177 |
- bazFound = true
|
|
178 |
- }
|
|
179 |
- }
|
|
180 |
- if !bazFound {
|
|
181 |
- t.Fatal("expected file baz.txt to be present, but not found")
|
|
182 |
- }
|
|
183 |
-
|
|
184 |
- // .terraform/file.txt would normally be ignored, but should not be
|
|
185 |
- var dotTerraformFileFound bool
|
|
186 |
- for _, file := range fileList {
|
|
187 |
- if file == ".terraform/file.txt" {
|
|
188 |
- dotTerraformFileFound = true
|
|
189 |
- }
|
|
190 |
- }
|
|
191 |
- if !dotTerraformFileFound {
|
|
192 |
- t.Fatal("expected file .terraform/file.txt to be present, but not found")
|
|
193 |
- }
|
|
194 |
-
|
|
195 |
- // Check the metadata
|
|
196 |
- expect := &Meta{
|
|
197 |
- Files: fileList,
|
|
198 |
- Size: slugSize,
|
|
199 |
- }
|
|
200 |
- if !reflect.DeepEqual(meta, expect) {
|
|
201 |
- t.Fatalf("\nexpect:\n%#v\n\nactual:\n%#v", expect, meta)
|
|
202 |
- }
|
|
203 |
-}
|
|
204 |
-
|
|
205 |
func TestPack_symlinks(t *testing.T) {
|
|
206 |
type tcase struct {
|
|
207 |
absolute bool
|
|
208 |
@@ -361,38 +164,6 @@
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
-func TestUnpack(t *testing.T) {
|
|
213 |
- // First create the slug file so we can try to unpack it.
|
|
214 |
- slug := bytes.NewBuffer(nil)
|
|
215 |
-
|
|
216 |
- if _, err := Pack("testdata/archive-dir", slug, true); err != nil {
|
|
217 |
- t.Fatalf("err: %v", err)
|
|
218 |
- }
|
|
219 |
-
|
|
220 |
- // Create a dir to unpack into.
|
|
221 |
- dst, err := ioutil.TempDir("", "slug")
|
|
222 |
- if err != nil {
|
|
223 |
- t.Fatalf("err: %v", err)
|
|
224 |
- }
|
|
225 |
- defer os.RemoveAll(dst)
|
|
226 |
-
|
|
227 |
- // Now try unpacking it.
|
|
228 |
- if err := Unpack(slug, dst); err != nil {
|
|
229 |
- t.Fatalf("err: %v", err)
|
|
230 |
- }
|
|
231 |
-
|
|
232 |
- // Verify all the files
|
|
233 |
- verifyFile(t, filepath.Join(dst, "bar.txt"), 0, "bar\n")
|
|
234 |
- verifyFile(t, filepath.Join(dst, "sub", "bar.txt"), os.ModeSymlink, "../bar.txt")
|
|
235 |
- verifyFile(t, filepath.Join(dst, "sub", "zip.txt"), 0, "zip\n")
|
|
236 |
-
|
|
237 |
- // Check that we can set permissions properly
|
|
238 |
- verifyPerms(t, filepath.Join(dst, "bar.txt"), 0644)
|
|
239 |
- verifyPerms(t, filepath.Join(dst, "sub", "zip.txt"), 0644)
|
|
240 |
- verifyPerms(t, filepath.Join(dst, "sub", "bar.txt"), 0644)
|
|
241 |
- verifyPerms(t, filepath.Join(dst, "exe"), 0755)
|
|
242 |
-}
|
|
243 |
-
|
|
244 |
func TestUnpackDuplicateNoWritePerm(t *testing.T) {
|
|
245 |
dir, err := ioutil.TempDir("", "slug")
|
|
246 |
if err != nil {
|
|
247 |
Index: golang-github-hashicorp-go-slug/terraformignore_test.go
|
|
248 |
===================================================================
|
|
249 |
--- golang-github-hashicorp-go-slug.orig/terraformignore_test.go 2023-02-05 11:43:28.699878054 +0100
|
|
250 |
+++ golang-github-hashicorp-go-slug/terraformignore_test.go 2023-02-05 11:46:33.927926898 +0100
|
|
251 |
@@ -11,104 +11,4 @@
|
|
252 |
t.Fatal("A directory without .terraformignore should get the default patterns")
|
|
253 |
}
|
|
254 |
|
|
255 |
- // load the .terraformignore file's patterns
|
|
256 |
- ignoreRules := parseIgnoreFile("testdata/archive-dir")
|
|
257 |
- type file struct {
|
|
258 |
- // the actual path, should be file path format /dir/subdir/file.extension
|
|
259 |
- path string
|
|
260 |
- // should match
|
|
261 |
- match bool
|
|
262 |
- }
|
|
263 |
- paths := []file{
|
|
264 |
- {
|
|
265 |
- path: ".terraform/",
|
|
266 |
- match: true,
|
|
267 |
- },
|
|
268 |
- {
|
|
269 |
- path: "included.txt",
|
|
270 |
- match: false,
|
|
271 |
- },
|
|
272 |
- {
|
|
273 |
- path: ".terraform/foo/bar",
|
|
274 |
- match: true,
|
|
275 |
- },
|
|
276 |
- {
|
|
277 |
- path: ".terraform/foo/bar/more/directories/so/many",
|
|
278 |
- match: true,
|
|
279 |
- },
|
|
280 |
- {
|
|
281 |
- path: ".terraform/foo/ignored-subdirectory/",
|
|
282 |
- match: true,
|
|
283 |
- },
|
|
284 |
- {
|
|
285 |
- path: "baz.txt",
|
|
286 |
- match: true,
|
|
287 |
- },
|
|
288 |
- {
|
|
289 |
- path: "parent/foo/baz.txt",
|
|
290 |
- match: true,
|
|
291 |
- },
|
|
292 |
- {
|
|
293 |
- path: "parent/foo/bar.tf",
|
|
294 |
- match: true,
|
|
295 |
- },
|
|
296 |
- {
|
|
297 |
- path: "parent/bar/bar.tf",
|
|
298 |
- match: false,
|
|
299 |
- },
|
|
300 |
- // baz.txt is ignored, but a file name including it should not be
|
|
301 |
- {
|
|
302 |
- path: "something/with-baz.txt",
|
|
303 |
- match: false,
|
|
304 |
- },
|
|
305 |
- {
|
|
306 |
- path: "something/baz.x",
|
|
307 |
- match: false,
|
|
308 |
- },
|
|
309 |
- // Getting into * patterns
|
|
310 |
- {
|
|
311 |
- path: "foo/ignored-doc.md",
|
|
312 |
- match: true,
|
|
313 |
- },
|
|
314 |
- // Should match [a-z] group
|
|
315 |
- {
|
|
316 |
- path: "bar/something-a.txt",
|
|
317 |
- match: true,
|
|
318 |
- },
|
|
319 |
- // ignore sub- terraform.d paths
|
|
320 |
- {
|
|
321 |
- path: "some-module/terraform.d/x",
|
|
322 |
- match: true,
|
|
323 |
- },
|
|
324 |
- // but not the root one
|
|
325 |
- {
|
|
326 |
- path: "terraform.d/",
|
|
327 |
- match: false,
|
|
328 |
- },
|
|
329 |
- {
|
|
330 |
- path: "terraform.d/foo",
|
|
331 |
- match: false,
|
|
332 |
- },
|
|
333 |
- // We ignore the directory, but a file of the same name could exist
|
|
334 |
- {
|
|
335 |
- path: "terraform.d",
|
|
336 |
- match: false,
|
|
337 |
- },
|
|
338 |
- // boop.text is ignored everywhere
|
|
339 |
- {
|
|
340 |
- path: "baz/boop.txt",
|
|
341 |
- match: true,
|
|
342 |
- },
|
|
343 |
- // except at current directory
|
|
344 |
- {
|
|
345 |
- path: "boop.txt",
|
|
346 |
- match: false,
|
|
347 |
- },
|
|
348 |
- }
|
|
349 |
- for i, p := range paths {
|
|
350 |
- match := matchIgnoreRule(p.path, ignoreRules)
|
|
351 |
- if match != p.match {
|
|
352 |
- t.Fatalf("%s at index %d should be %t", p.path, i, p.match)
|
|
353 |
- }
|
|
354 |
- }
|
|
355 |
}
|