forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
parallel_test.go
122 lines (108 loc) · 2.18 KB
/
parallel_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package testcontainers
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestParallelContainers(t *testing.T) {
tests := []struct {
name string
reqs ParallelContainerRequest
resLen int
expErrors int
}{
{
name: "running two containers (one error)",
reqs: ParallelContainerRequest{
{
ContainerRequest: ContainerRequest{
Image: "nginx",
ExposedPorts: []string{
"10080/tcp",
},
},
Started: true,
},
{
ContainerRequest: ContainerRequest{
Image: "bad bad bad",
ExposedPorts: []string{
"10081/tcp",
},
},
Started: true,
},
},
resLen: 1,
expErrors: 1,
},
{
name: "running two containers (all errors)",
reqs: ParallelContainerRequest{
{
ContainerRequest: ContainerRequest{
Image: "bad bad bad",
ExposedPorts: []string{
"10081/tcp",
},
},
Started: true,
},
{
ContainerRequest: ContainerRequest{
Image: "bad bad bad",
ExposedPorts: []string{
"10081/tcp",
},
},
Started: true,
},
},
resLen: 0,
expErrors: 2,
},
{
name: "running two containers (success)",
reqs: ParallelContainerRequest{
{
ContainerRequest: ContainerRequest{
Image: "nginx",
ExposedPorts: []string{
"10080/tcp",
},
},
Started: true,
},
{
ContainerRequest: ContainerRequest{
Image: "nginx",
ExposedPorts: []string{
"10081/tcp",
},
},
Started: true,
},
},
resLen: 2,
expErrors: 0,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
res, err := ParallelContainers(context.Background(), tc.reqs, ParallelContainersOptions{})
if err != nil {
require.NotZero(t, tc.expErrors)
e, _ := err.(ParallelContainersError)
if len(e.Errors) != tc.expErrors {
t.Fatalf("expected erorrs: %d, got: %d\n", tc.expErrors, len(e.Errors))
}
}
for _, c := range res {
defer c.Terminate(context.Background())
}
if len(res) != tc.resLen {
t.Fatalf("expected containers: %d, got: %d\n", tc.resLen, len(res))
}
})
}
}