Skip to content

Commit bfa5591

Browse files
edoardocomardnwe
authored andcommitted
refactor(tests): enhance tearDownDockerTestEnvironment to support zookeeper profile for Kafka versions < 4.0.0
This update modifies the `tearDownDockerTestEnvironment` function to conditionally include the zookeeper profile in Docker commands when the Kafka version is less than 4.0.0. This ensures proper shutdown of zookeeper containers, improving the reliability of the test environment teardown process. Signed-off-by: Edoardo Comar <ecomar@uk.ibm.com>
1 parent 6cba260 commit bfa5591

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

functional_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,22 @@ func existingEnvironment(ctx context.Context, env *testEnvironment) (bool, error
283283
}
284284

285285
func tearDownDockerTestEnvironment(ctx context.Context, env *testEnvironment) error {
286-
c := exec.Command("docker", "compose", "down", "--volumes")
286+
args := []string{"compose", "down", "--volumes"}
287+
v, _ := ParseKafkaVersion(env.KafkaVersion)
288+
// use zookeeper profile for kafka < 4 to ensure zookeeper containers are stopped
289+
if !v.IsAtLeast(V4_0_0_0) {
290+
args = append([]string{"compose", "--profile", "zookeeper"}, args[1:]...)
291+
}
292+
c := exec.Command("docker", args...)
287293
c.Stdout = os.Stdout
288294
c.Stderr = os.Stderr
289295
downErr := c.Run()
290296

291-
c = exec.Command("docker", "compose", "rm", "-v", "--force", "--stop")
297+
args = []string{"compose", "rm", "-v", "--force", "--stop"}
298+
if !v.IsAtLeast(V4_0_0_0) {
299+
args = append([]string{"compose", "--profile", "zookeeper"}, args[1:]...)
300+
}
301+
c = exec.Command("docker", args...)
292302
c.Stdout = os.Stdout
293303
c.Stderr = os.Stderr
294304
rmErr := c.Run()

0 commit comments

Comments
 (0)