Skip to content

Commit

Permalink
add tests for container parallell runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Stepanov committed Jun 13, 2022
1 parent cfb9bfc commit e9cc2ac
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions generic_test.go
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))
}
})
}
}

0 comments on commit e9cc2ac

Please sign in to comment.