forked from smartcontractkit/chainlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
65 lines (55 loc) · 1.38 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
package main
import (
"embed"
"io/fs"
"os"
"testing"
"github.com/rogpeppe/go-internal/testscript"
"github.com/stretchr/testify/require"
"github.com/smartcontractkit/chainlink/v2/core"
v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/static"
)
//go:embed testdata/**
var testFs embed.FS
func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"chainlink": core.Main,
}))
}
func TestScripts(t *testing.T) {
t.Parallel()
testDataRootDir := "testdata/scripts"
visitFn := func(path string, d os.DirEntry, err error) error {
t.Logf("path %s", path)
if err != nil {
return err
}
if d.IsDir() && hasScripts(t, path) {
t.Run(path, func(t *testing.T) {
t.Parallel()
testscript.Run(t, testscript.Params{
Dir: path,
Setup: commonEnv(t),
})
})
}
return nil
}
require.NoError(t, fs.WalkDir(testFs, testDataRootDir, visitFn))
}
func hasScripts(t *testing.T, dir string) bool {
t.Helper()
matches, err := fs.Glob(os.DirFS(dir), "*txtar")
require.NoError(t, err)
return len(matches) > 0
}
func commonEnv(t *testing.T) func(env *testscript.Env) error {
return func(env *testscript.Env) error {
env.Setenv(string(v2.EnvDev), "true")
env.Setenv("HOME", "$WORK/home")
env.Setenv("VERSION", static.Version)
env.Setenv("COMMIT_SHA", static.Sha)
return nil
}
}