/
examples.go
57 lines (48 loc) · 1.26 KB
/
examples.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
package examples
import (
"context"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
blimpAssert "github.com/kelda/blimp/ci/assert"
"github.com/kelda/blimp/ci/util"
)
type Test struct {
Name string
WorkingDir string
UpArgs []string
Tests []blimpAssert.Test
}
func (test Test) GetName() string {
return test.Name
}
func (test Test) Run(ctx context.Context, t *testing.T) {
if test.WorkingDir != "" {
require.NoError(t, os.Chdir(test.WorkingDir), "set working directory for test")
}
testCtx, cancelTest := context.WithCancel(ctx)
upCtx, cancelUp := context.WithCancel(testCtx)
waitErr, err := util.Up(upCtx, test.UpArgs...)
require.NoError(t, err, "start blimp up")
exited := make(chan bool)
go func() {
assert.NoError(t, <-waitErr, "run blimp up")
cancelTest()
exited <- true
}()
defer func() {
cancelUp()
// Wait for the process to exit before moving to the next test.
<-exited
}()
// Wait for the service to start listening (it takes some time for the
// service to actually initialize and bind to the port within the container).
time.Sleep(20 * time.Second)
for _, test := range test.Tests {
t.Run(test.GetName(), func(t *testing.T) {
test.Run(testCtx, t)
})
}
}