@@ -18,6 +18,7 @@ import (
1818 "go.mongodb.org/mongo-driver/v2/x/mongo/driver/connstring"
1919
2020 "github.com/testcontainers/testcontainers-go"
21+ "github.com/testcontainers/testcontainers-go/exec"
2122 "github.com/testcontainers/testcontainers-go/modules/mongodb/atlaslocal"
2223)
2324
@@ -560,18 +561,16 @@ func TestConnectionString(t *testing.T) {
560561func requireEnvVar (t * testing.T , ctr testcontainers.Container , envVarName , expected string ) {
561562 t .Helper ()
562563
563- exitCode , reader , err := ctr .Exec (context .Background (), []string {"sh" , "-c" , "echo $" + envVarName })
564+ // testcontainers-go's Exec() returns a multiplexed stream in the same format
565+ // used by the Docker API. Each frame is prefixed with an 8-byte header.
566+ exitCode , reader , err := ctr .Exec (context .Background (), []string {"sh" , "-c" , "echo $" + envVarName }, exec .Multiplexed ())
564567 require .NoError (t , err )
565568 require .Equal (t , 0 , exitCode )
566569
567570 outBytes , err := io .ReadAll (reader )
568571 require .NoError (t , err )
569572
570- // testcontainers-go's Exec() returns a multiplexed stream in the same format
571- // used by the Docker API. Each frame is prefixed with an 8-byte header.
572- require .Greater (t , len (outBytes ), 8 , "Exec output too short to contain env var value" )
573-
574- out := strings .TrimSpace (string (outBytes [8 :]))
573+ out := strings .TrimSpace (string (outBytes ))
575574 require .Equal (t , expected , out , "DO_NOT_TRACK env var value mismatch" )
576575}
577576
@@ -727,7 +726,7 @@ func requireInitScriptsExist(t *testing.T, ctr testcontainers.Container, expecte
727726
728727 const dstDir = "/docker-entrypoint-initdb.d"
729728
730- exit , r , err := ctr .Exec (context .Background (), []string {"sh" , "-lc" , "ls -l " + dstDir })
729+ exit , r , err := ctr .Exec (context .Background (), []string {"sh" , "-lc" , "ls -l " + dstDir }, exec . Multiplexed () )
731730 require .NoError (t , err )
732731
733732 // If the map is empty, the command returns exit code 2.
@@ -764,11 +763,13 @@ func requireInitScriptsDoesNotExist(t *testing.T, ctr testcontainers.Container,
764763 // Sanity check to verify that all scripts are present.
765764 for filename := range expectedScripts {
766765 cmd := []string {"sh" , "-lc" , "ls -1 /docker-entrypoint-initdb.d 2>/dev/null || true" }
767- _ , reader , err := ctr .Exec (context .Background (), cmd )
766+ _ , reader , err := ctr .Exec (context .Background (), cmd , exec .Multiplexed ())
767+ require .NoError (t , err )
768+
769+ raw , err := io .ReadAll (reader )
768770 require .NoError (t , err )
769771
770- content , _ := io .ReadAll (reader )
771- require .NotContains (t , string (content ), filename )
772+ require .NotContains (t , string (raw ), filename )
772773 }
773774}
774775
0 commit comments