forked from testcontainers/testcontainers-go
/
exit_test.go
51 lines (41 loc) · 1.18 KB
/
exit_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
package wait
import (
"context"
"io"
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/go-connections/nat"
tcexec "github.com/testcontainers/testcontainers-go/exec"
)
type exitStrategyTarget struct {
isRunning bool
}
func (st exitStrategyTarget) Host(ctx context.Context) (string, error) {
return "", nil
}
func (st exitStrategyTarget) Ports(ctx context.Context) (nat.PortMap, error) {
return nil, nil
}
func (st exitStrategyTarget) MappedPort(ctx context.Context, n nat.Port) (nat.Port, error) {
return n, nil
}
func (st exitStrategyTarget) Logs(ctx context.Context) (io.ReadCloser, error) {
return nil, nil
}
func (st exitStrategyTarget) Exec(ctx context.Context, cmd []string, options ...tcexec.ProcessOption) (int, io.Reader, error) {
return 0, nil, nil
}
func (st exitStrategyTarget) State(ctx context.Context) (*types.ContainerState, error) {
return &types.ContainerState{Running: st.isRunning}, nil
}
func TestWaitForExit(t *testing.T) {
target := exitStrategyTarget{
isRunning: false,
}
wg := NewExitStrategy().WithExitTimeout(100 * time.Millisecond)
err := wg.WaitUntilReady(context.Background(), target)
if err != nil {
t.Fatal(err)
}
}