-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_test.go
75 lines (56 loc) · 1.43 KB
/
container_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
//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 TestContainerRun(t *testing.T) {
r := require.New(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
c, err := NewContainer(
"test-container",
images.EchoServer,
nil,
NewEnvironment().
StringVar("ADDR", ":5555").
LogLevelVar("LOG_LEVEL", log.TraceLevel),
NewPortBindings().
PortDNAT(ProtoTCP, 5555),
)
r.NoError(err)
defer c.Close(ctx)
err = c.Ping(ctx)
r.NoError(err)
err = c.Run(ctx)
r.NoError(err)
err = c.AwaitOutput(ctx, NewSubstringMatcher("running GRPC echo server"))
r.NoError(err)
defer c.Close(ctx)
hp, err := c.URL(ProtoTCP, 5555)
r.NoError(err)
dial, err := grpc.Dial(hp.String(), grpc.WithInsecure())
r.NoError(err)
cli := proto.NewEchoServiceClient(dial)
resp, err := cli.Echo(ctx, &proto.EchoRequest{
Message: "test message",
})
r.NoError(err)
r.Equal("test message", resp.GetMessage())
err = c.AwaitOutput(ctx, NewSubstringMatcher(`test message`))
r.NoError(err)
resp, err = cli.Echo(ctx, &proto.EchoRequest{
Message: "some another message",
})
r.NoError(err)
r.Equal("some another message", resp.GetMessage())
}