-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
51 lines (45 loc) · 1.05 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
package main
import (
"os"
"path/filepath"
"testing"
"github.com/rogpeppe/go-internal/testscript"
)
func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"kubemodcmp": func() (exitCode int) {
defer func() {
if val := recover(); val != nil {
exitCode = recover().(int)
}
}()
main()
return 0
},
}))
}
func TestScript(t *testing.T) {
testscript.Run(t, testscript.Params{
Dir: "testdata",
TestWork: true,
Setup: func(env *testscript.Env) error {
path := os.Getenv("GOPATH")
if os.Getenv("GOPATH") == "" {
path = filepath.Join(env.WorkDir, ".go")
}
env.Setenv("GOPATH", path)
if os.Getenv("GOCACHE") != "" {
env.Setenv("GOCACHE", os.Getenv("GOCACHE"))
} else {
env.Setenv("GOCACHE", filepath.Join(path, "cache"))
}
// TODO: Use global cache instead of one per txtar
if os.Getenv("GOMODCACHE") != "" {
env.Setenv("GOMODCACHE", os.Getenv("GOMODCACHE"))
} else {
env.Setenv("GOMODCACHE", filepath.Join(path, "modcache"))
}
return nil
},
})
}