-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_test.go
87 lines (69 loc) · 1.73 KB
/
group_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
83
84
85
86
87
//go:build docker
package docker
import (
"context"
"testing"
"time"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"github.com/teran/echo-grpc-server/presenter/proto"
"github.com/teran/go-docker-testsuite/images"
)
func init() {
log.SetLevel(log.TraceLevel)
}
func TestGroup(t *testing.T) {
r := require.New(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
awaitRunFn := func(ctx context.Context, ht HookType, c Container) error {
if ht == HookTypeAfterRun {
return c.AwaitOutput(ctx, NewSubstringMatcher("running GRPC echo server"))
}
return nil
}
apps := []*Application{}
c1, err := NewContainer(
"server",
images.EchoServer,
nil,
NewEnvironment().
StringVar("ADDR", ":5555").
LogLevelVar("LOG_LEVEL", log.TraceLevel),
NewPortBindings().
PortDNAT(ProtoTCP, 5555),
)
r.NoError(err)
apps = append(apps, NewApplication(c1, awaitRunFn))
c2, err := NewContainer(
"client",
images.EchoServer,
nil,
NewEnvironment().
StringVar("ADDR", ":5555").
LogLevelVar("LOG_LEVEL", log.TraceLevel),
NewPortBindings().
PortDNAT(ProtoTCP, 5555),
)
r.NoError(err)
apps = append(apps, NewApplication(c2, awaitRunFn))
g, err := NewGroup("test-group", apps...)
r.NoError(err)
defer g.Close(ctx)
err = g.Run(ctx)
r.NoError(err)
cl, err := c2.URL(ProtoTCP, 5555)
r.NoError(err)
dial, err := grpc.Dial(cl.String(), grpc.WithInsecure())
r.NoError(err)
cli := proto.NewRemoteEchoServiceClient(dial)
resp, err := cli.RemoteEcho(ctx, &proto.RemoteEchoRequest{
Remote: "server:5555",
Message: "test message",
})
r.NoError(err)
r.Equal("test message", resp.GetMessage())
err = g.Close(ctx)
r.NoError(err)
}