From e9cc2ac8bc8b0566cdf48a71196ecb3b0ac7da89 Mon Sep 17 00:00:00 2001 From: Vladimir Stepanov Date: Mon, 13 Jun 2022 22:11:31 +0600 Subject: [PATCH] add tests for container parallell runner --- generic_test.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 generic_test.go diff --git a/generic_test.go b/generic_test.go new file mode 100644 index 0000000000..a070aff50c --- /dev/null +++ b/generic_test.go @@ -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)) + } + }) + } +}