forked from matrix-org/complement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.go
64 lines (57 loc) · 2.17 KB
/
test_main.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
package complement
import (
"fmt"
"os"
"testing"
"github.com/matrix-org/complement/b"
)
var testPackage *TestPackage
// TestMain is the main entry point for Complement.
//
// It will clean up any old containers/images/networks from the previous run, then run the tests, then clean up
// again. No blueprints are made at this point as they are lazily made on demand.
//
// The 'namespace' should be unique for this test package, among all test packages which may run in parallel, to avoid
// docker containers stepping on each other. For MSCs, use the MSC name. For versioned releases, use the version number
// along with any sub-directory name.
func TestMain(m *testing.M, namespace string) {
TestMainWithCleanup(m, namespace, nil)
}
// TestMainWithCleanup is TestMain but with a cleanup function prior to terminating the test suite.
// This function should be used for per-suite cleanup operations e.g tearing down containers, killing
// child processes, etc.
func TestMainWithCleanup(m *testing.M, namespace string, cleanup func()) {
var err error
testPackage, err = NewTestPackage(namespace)
if err != nil {
fmt.Printf("Error: %s", err)
os.Exit(1)
}
exitCode := m.Run()
testPackage.Cleanup()
if cleanup != nil {
cleanup()
}
os.Exit(exitCode)
}
// Deploy will deploy the given blueprint or terminate the test.
// It will construct the blueprint if it doesn't already exist in the docker image cache.
// This function is the main setup function for all tests as it provides a deployment with
// which tests can interact with.
func OldDeploy(t *testing.T, blueprint b.Blueprint) Deployment {
t.Helper()
if testPackage == nil {
t.Fatalf("Deploy: testPackage not set, did you forget to call complement.TestMain?")
}
return testPackage.OldDeploy(t, blueprint)
}
// Deploy will deploy the given number of servers or terminate the test.
// This function is the main setup function for all tests as it provides a deployment with
// which tests can interact with.
func Deploy(t *testing.T, numServers int) Deployment {
t.Helper()
if testPackage == nil {
t.Fatalf("Deploy: testPackage not set, did you forget to call complement.TestMain?")
}
return testPackage.Deploy(t, numServers)
}