-
Notifications
You must be signed in to change notification settings - Fork 88
/
generate.go
48 lines (39 loc) · 1.17 KB
/
generate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package upload
import (
"os"
"path"
"github.com/mholt/archiver/v3"
"github.com/otiai10/copy"
"github.com/pkg/errors"
)
// GenerateTest will create a new upload test fixture for integration tests
func GenerateTest(name string, applicationPath string) error {
testRoot := path.Join("integration", "upload", "tests", name)
if err := os.MkdirAll(testRoot, 0755); err != nil {
return errors.Wrap(err, "failed to create test root")
}
inputRoot := path.Join(testRoot, "input")
if err := os.MkdirAll(inputRoot, 0755); err != nil {
return errors.Wrap(err, "failed to create input root")
}
err := copy.Copy(applicationPath, inputRoot)
if err != nil {
return errors.Wrap(err, "failed to copy input")
}
// Create the expected archive
tarGz := archiver.TarGz{
Tar: &archiver.Tar{
ImplicitTopLevelFolder: true,
},
}
paths := []string{
path.Join(applicationPath, "upstream"),
path.Join(applicationPath, "base"),
path.Join(applicationPath, "overlays"),
path.Join(applicationPath, "skippedFiles"),
}
if err := tarGz.Archive(paths, path.Join(testRoot, "expected-archive.tar.gz")); err != nil {
return errors.Wrap(err, "failed to create tar gz")
}
return nil
}