-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
66 lines (55 loc) · 1.22 KB
/
main_test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"os"
"path/filepath"
"testing"
"github.com/rogpeppe/go-internal/testscript"
)
func TestHarpoon(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "tests",
//Cmds: customCommands(),
RequireExplicitExec: true,
Setup: func(env *testscript.Env) error {
existingDir := filepath.Join("tests", "testcases")
destDir := filepath.Join(env.WorkDir, "testcases")
// Copy the directory to the test environment
err := copyDir(existingDir, destDir)
if err != nil {
return err
}
env.Setenv("GOCOVERDIR", "/tmp/integration")
return nil
},
})
}
// copyDir copies the contents of src to dst
func copyDir(src string, dst string) error {
entries, err := os.ReadDir(src)
if err != nil {
return err
}
if err := os.MkdirAll(dst, 0755); err != nil {
return err
}
for _, entry := range entries {
srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name())
if entry.IsDir() {
err = copyDir(srcPath, dstPath)
if err != nil {
return err
}
continue
}
data, err := os.ReadFile(srcPath)
if err != nil {
return err
}
err = os.WriteFile(dstPath, data, 0644)
if err != nil {
return err
}
}
return nil
}