forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for container parallell runner
- Loading branch information
Vladimir Stepanov
committed
Jun 13, 2022
1 parent
cfb9bfc
commit e9cc2ac
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package testcontainers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestGenericParallelContainers(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
reqs []GenericContainerRequest | ||
resLen int | ||
expErrors int | ||
}{ | ||
{ | ||
name: "running two containers (success)", | ||
reqs: []GenericContainerRequest{ | ||
{ | ||
ContainerRequest: ContainerRequest{ | ||
|
||
Image: "nginx", | ||
ExposedPorts: []string{ | ||
"10080/tcp", | ||
}, | ||
}, | ||
Started: true, | ||
}, | ||
{ | ||
ContainerRequest: ContainerRequest{ | ||
|
||
Image: "nginx", | ||
ExposedPorts: []string{ | ||
"10081/tcp", | ||
}, | ||
}, | ||
Started: true, | ||
}, | ||
}, | ||
resLen: 2, | ||
}, | ||
{ | ||
name: "running two containers (one error)", | ||
reqs: []GenericContainerRequest{ | ||
{ | ||
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, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
res, err := GenericParallelContainers(context.Background(), tc.reqs) | ||
|
||
if err != nil && tc.expErrors > 0 { | ||
e, _ := err.(GenericParallelErrors) | ||
|
||
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)) | ||
} | ||
}) | ||
} | ||
} |