-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathacceptance_test.go
82 lines (64 loc) · 1.77 KB
/
acceptance_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package acceptance
import (
"fmt"
"os"
"runtime"
"testing"
"github.com/circleci/ex/testing/compiler"
"github.com/circleci/ex/testing/testcontext"
)
var (
orchestratorTestBinary = os.Getenv("ORCHESTRATOR_TEST_BINARY")
orchestratorTestBinaryRunTask = ""
binariesPath = ""
taskAgentBinary = ""
)
func TestMain(m *testing.M) {
status, err := runTests(m)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
os.Exit(status)
}
func runTests(m *testing.M) (int, error) {
ctx := testcontext.Background()
p := compiler.NewParallel(runtime.NumCPU())
defer p.Cleanup()
binariesPath = p.Dir()
// Init binaries
p.Add(compiler.Work{
Result: &orchestratorTestBinary,
Name: "orchestrator",
Target: "..",
Source: "github.com/circleci/runner-init/cmd/orchestrator",
})
// Fakes
p.Add(compiler.Work{
Result: &taskAgentBinary,
Name: "task-agent",
Target: "..",
Source: "github.com/circleci/runner-init/internal/testing/faketaskagent",
})
err := p.Run(ctx)
if err != nil {
return 0, err
}
fmt.Printf("Using 'orchestrator' test binary: %q\n", orchestratorTestBinary)
fmt.Printf("Using fake 'task-agent' test binary: %q\n", taskAgentBinary)
if err := createRunTaskScript(); err != nil {
return 0, err
}
fmt.Printf("Using 'orchestrator run-task' script: %q\n", orchestratorTestBinaryRunTask)
return m.Run(), nil
}
// A little hack to get around limitations of the test runner on positional arguments
func createRunTaskScript() error {
script := "#!/bin/bash\nexec " + orchestratorTestBinary + " run-task"
scriptPath := binariesPath + "/orchestratorRunTask.sh"
if err := os.WriteFile(scriptPath, []byte(script), 0750); err != nil { //nolint:gosec
return err
}
orchestratorTestBinaryRunTask = scriptPath
return nil
}