33import org .assertj .core .api .Assumptions ;
44import org .junit .jupiter .api .AutoClose ;
55import org .junit .jupiter .api .Test ;
6+ import org .junit .jupiter .params .ParameterizedTest ;
7+ import org .junit .jupiter .params .provider .NullSource ;
8+ import org .junit .jupiter .params .provider .ValueSource ;
69import org .testcontainers .TestImages ;
710import org .testcontainers .containers .ExecConfig ;
811import org .testcontainers .containers .GenericContainer ;
912import org .testcontainers .utility .TestEnvironment ;
1013
14+ import java .io .IOException ;
1115import java .util .Collections ;
1216
1317import static org .assertj .core .api .Assertions .assertThat ;
@@ -36,6 +40,19 @@ void shouldExecuteCommand() throws Exception {
3640 // We expect to reach this point for modern Docker versions.
3741 }
3842
43+ @ ParameterizedTest
44+ @ NullSource
45+ @ ValueSource (strings = {"" , " " , " " })
46+ void shouldExecuteCommandAndSkipCommand (String commandParam ) throws Exception {
47+ Assumptions .assumeThat (TestEnvironment .dockerExecutionDriverSupportsExec ()).isTrue ();
48+
49+ final GenericContainer .ExecResult result = redis .execInContainer ("redis-cli" , commandParam , "role" );
50+ assertThat (result .getStdout ())
51+ .as ("Output for \" redis-cli role\" command should start with \" master\" " )
52+ .startsWith ("master" );
53+ assertThat (result .getStderr ()).as ("Stderr for \" redis-cli role\" command should be empty" ).isEmpty ();
54+ }
55+
3956 @ Test
4057 void shouldExecuteCommandWithUser () throws Exception {
4158 // The older "lxc" execution driver doesn't support "exec". At the time of writing (2016/03/29),
@@ -56,7 +73,7 @@ void shouldExecuteCommandWithWorkdir() throws Exception {
5673 Assumptions .assumeThat (TestEnvironment .dockerExecutionDriverSupportsExec ()).isTrue ();
5774
5875 final GenericContainer .ExecResult result = redis .execInContainer (
59- ExecConfig .builder ().workDir ("/opt" ).command (new String [] { "pwd" }).build ()
76+ ExecConfig .builder ().workDir ("/opt" ).command (new String []{ "pwd" }).build ()
6077 );
6178 assertThat (result .getStdout ()).startsWith ("/opt" );
6279 }
@@ -69,9 +86,29 @@ void shouldExecuteCommandWithEnvVars() throws Exception {
6986 ExecConfig
7087 .builder ()
7188 .envVars (Collections .singletonMap ("TESTCONTAINERS" , "JAVA" ))
72- .command (new String [] { "env" })
89+ .command (new String []{ "env" })
7390 .build ()
7491 );
7592 assertThat (result .getStdout ()).contains ("TESTCONTAINERS=JAVA" );
7693 }
94+
95+
96+ private GenericContainer minioContainer ;
97+
98+ void testIt () throws IOException , InterruptedException {
99+ minioContainer .execInContainer (
100+ "mc" , debug (),
101+ "mb" , "--region=eu-central-1" ,
102+ "$alias/mynewbucket"
103+ );
104+ }
105+
106+ private String debug () {
107+ if (false ) {
108+ return "--debug" ;
109+ } else {
110+ return "" ;
111+ }
112+ }
113+
77114}
0 commit comments