Skip to content

Commit ffcb8b6

Browse files
authored
chore: use testcontainers.RequireContainerExec (#2870)
Use testcontainers.RequireContainerExec to simplify tests. Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent 8283ba8 commit ffcb8b6

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

modules/kafka/kafka_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package kafka_test
22

33
import (
44
"context"
5-
"io"
65
"strings"
76
"testing"
87

@@ -82,15 +81,11 @@ func assertAdvertisedListeners(t *testing.T, container testcontainers.Container)
8281
inspect, err := container.Inspect(context.Background())
8382
require.NoError(t, err)
8483

85-
hostname := inspect.Config.Hostname
84+
brokerURL := "BROKER://" + inspect.Config.Hostname + ":9092"
8685

87-
code, r, err := container.Exec(context.Background(), []string{"cat", "/usr/sbin/testcontainers_start.sh"})
88-
require.NoError(t, err)
89-
90-
require.Zero(t, code)
86+
ctx := context.Background()
9187

92-
bs, err := io.ReadAll(r)
93-
require.NoError(t, err)
88+
bs := testcontainers.RequireContainerExec(ctx, t, container, []string{"cat", "/usr/sbin/testcontainers_start.sh"})
9489

95-
require.Containsf(t, string(bs), "BROKER://"+hostname+":9092", "expected advertised listeners to contain %s, got %s", "BROKER://"+hostname+":9092", string(bs))
90+
require.Containsf(t, bs, brokerURL, "expected advertised listeners to contain %s, got %s", brokerURL, bs)
9691
}

modules/neo4j/neo4j_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package neo4j_test
33
import (
44
"context"
55
"fmt"
6-
"io"
76
"strings"
87
"testing"
98

@@ -159,12 +158,7 @@ func createDriver(t *testing.T, ctx context.Context, container *neo4j.Neo4jConta
159158

160159
func getContainerEnv(t *testing.T, ctx context.Context, container *neo4j.Neo4jContainer) string {
161160
t.Helper()
162-
exec, reader, err := container.Exec(ctx, []string{"env"})
163-
require.NoErrorf(t, err, "expected env to successfully run but did not")
164-
require.Zerof(t, exec, "expected env to exit with status 0 but exited with: %d", exec)
165-
envVars, err := io.ReadAll(reader)
166-
require.NoErrorf(t, err, "expected to read all bytes from env output but did not")
167-
return string(envVars)
161+
return testcontainers.RequireContainerExec(ctx, t, container, []string{"env"})
168162
}
169163

170164
const logSeparator = "---$$$---"

0 commit comments

Comments
 (0)