11package org .testcontainers .containers ;
22
3- import org .testcontainers .utility .MountableFile ;
4- import org .yaml .snakeyaml .Yaml ;
5-
63import java .io .IOException ;
74import java .nio .file .Paths ;
85import java .util .concurrent .ExecutionException ;
96
7+ import org .testcontainers .utility .MountableFile ;
8+ import org .yaml .snakeyaml .Yaml ;
109import static org .testcontainers .containers .PathUtils .normalizePath ;
1110
1211/**
@@ -23,44 +22,46 @@ public final class TarantoolContainerClientHelper {
2322
2423 private final TarantoolContainerOperations <? extends Container <?>> container ;
2524 private final String EXECUTE_SCRIPT_ERROR_TEMPLATE =
26- "Executed script %s with exit code %d, stderr: \" %s\" , stdout: \" %s\" " ;
25+ "Executed script %s with exit code %d, stderr: \" %s\" , stdout: \" %s\" " ;
2726 private static final String EXECUTE_COMMAND_ERROR_TEMPLATE =
28- "Executed command \" %s\" with exit code %d, stderr: \" %s\" , stdout: \" %s\" " ;
27+ "Executed command \" %s\" with exit code %d, stderr: \" %s\" , stdout: \" %s\" " ;
2928 private static final String MTLS_COMMAND_TEMPLATE =
30- "echo \" " +
31- " print(require('yaml').encode( " +
32- " {require('net.box').connect( " +
33- " { uri='%s:%d', params = { transport='ssl', ssl_key_file = '%s', ssl_cert_file = '%s' }}, " +
34- " { user = '%s', password = '%s' } " +
35- " ):eval('%s')}) " +
36- " ); " +
37- " os.exit(); " +
38- "\" | tarantool" ;
29+ "echo \" " +
30+ " print(require('yaml').encode( " +
31+ " {require('net.box').connect( " +
32+ " { uri='%s:%d', params = { transport='ssl', ssl_key_file = '%s', ssl_cert_file = '%s'" +
33+ " }}, " +
34+ " { user = '%s', password = '%s' } " +
35+ " ):eval('%s')}) " +
36+ " ); " +
37+ " os.exit(); " +
38+ "\" | tarantool" ;
3939 private static final String SSL_COMMAND_TEMPLATE =
40- "echo \" " +
41- " print(require('yaml').encode( " +
42- " {require('net.box').connect( " +
43- " { uri='%s:%d', params = { transport='ssl' }}, " +
40+ "echo \" " +
41+ " print(require('yaml').encode( " +
42+ " {require('net.box').connect( " +
43+ " { uri='%s:%d', params = { transport='ssl' }}, " +
44+ " { user = '%s', password = '%s' } " +
45+ " ):eval('%s')}) " +
46+ " ); " +
47+ " os.exit(); " +
48+ "\" | tarantool" ;
49+ private static final String COMMAND_TEMPLATE = "echo \" " +
50+ " print(require('yaml').encode( " +
51+ " {require('net.box').connect( " +
52+ " { uri='%s:%d' }, " +
4453 " { user = '%s', password = '%s' } " +
4554 " ):eval('%s')}) " +
46- " ); " +
47- " os.exit(); " +
48- "\" | tarantool" ;
49- private static final String COMMAND_TEMPLATE = "echo \" " +
50- " print(require('yaml').encode( " +
51- " {require('net.box').connect( " +
52- " { uri='%s:%d' }, " +
53- " { user = '%s', password = '%s' } " +
54- " ):eval('%s')}) " +
55- " ); " +
56- " os.exit(); " +
57- "\" | tarantool" ;
55+ " ); " +
56+ " os.exit(); " +
57+ "\" | tarantool" ;
5858
5959 TarantoolContainerClientHelper (TarantoolContainerOperations <? extends Container <?>> container ) {
6060 this .container = container ;
6161 }
62-
63- public Container .ExecResult executeScript (String scriptResourcePath , SslContext sslContext ) throws IOException , InterruptedException {
62+
63+ public Container .ExecResult executeScript (String scriptResourcePath , SslContext sslContext )
64+ throws IOException , InterruptedException {
6465 if (!container .isRunning ()) {
6566 throw new IllegalStateException ("Cannot execute scripts in stopped container" );
6667 }
@@ -71,27 +72,29 @@ public Container.ExecResult executeScript(String scriptResourcePath, SslContext
7172 return executeCommand (String .format ("return dofile('%s')" , containerPath ), sslContext );
7273 }
7374
74- public <T > T executeScriptDecoded (String scriptResourcePath , SslContext sslContext ) throws IOException , InterruptedException , ExecutionException {
75+ public <T > T executeScriptDecoded (String scriptResourcePath , SslContext sslContext )
76+ throws IOException , InterruptedException , ExecutionException {
7577 Container .ExecResult result = executeScript (scriptResourcePath , sslContext );
7678
7779 if (result .getExitCode () != 0 ) {
7880
7981 if (result .getExitCode () == 3 || result .getExitCode () == 1 ) {
8082 throw new ExecutionException (String .format (EXECUTE_SCRIPT_ERROR_TEMPLATE ,
81- scriptResourcePath , result .getExitCode (),
82- result .getStderr (), result .getStdout ()),
83- new Throwable ());
83+ scriptResourcePath , result .getExitCode (),
84+ result .getStderr (), result .getStdout ()),
85+ new Throwable ());
8486 }
8587
8688 throw new IllegalStateException (String .format (EXECUTE_SCRIPT_ERROR_TEMPLATE ,
87- scriptResourcePath , result .getExitCode (),
88- result .getStderr (), result .getStdout ()));
89+ scriptResourcePath , result .getExitCode (),
90+ result .getStderr (), result .getStdout ()));
8991 }
9092
9193 return yaml .load (result .getStdout ());
9294 }
9395
94- public Container .ExecResult executeCommand (String command , SslContext sslContext ) throws IOException , InterruptedException {
96+ public Container .ExecResult executeCommand (String command , SslContext sslContext )
97+ throws IOException , InterruptedException {
9598 if (!container .isRunning ()) {
9699 throw new IllegalStateException ("Cannot execute commands in stopped container" );
97100 }
@@ -102,22 +105,22 @@ public Container.ExecResult executeCommand(String command, SslContext sslContext
102105 String bashCommand ;
103106 if (sslContext == null ) { // No SSL
104107 bashCommand = String .format (COMMAND_TEMPLATE ,
105- container .getHost (), container .getInternalPort (),
106- container .getUsername (), container .getPassword (),
107- command
108+ container .getHost (), container .getInternalPort (),
109+ container .getUsername (), container .getPassword (),
110+ command
108111 );
109112 } else if (sslContext .getKeyFile () != null && sslContext .getCertFile () != null ) { // mTLS
110113 bashCommand = String .format (MTLS_COMMAND_TEMPLATE ,
111- container .getHost (), container .getInternalPort (),
112- sslContext .getKeyFile (), sslContext .getCertFile (),
113- container .getUsername (), container .getPassword (),
114- command
114+ container .getHost (), container .getInternalPort (),
115+ sslContext .getKeyFile (), sslContext .getCertFile (),
116+ container .getUsername (), container .getPassword (),
117+ command
115118 );
116119 } else { // SSL
117120 bashCommand = String .format (SSL_COMMAND_TEMPLATE ,
118- container .getHost (), container .getInternalPort (),
119- container .getUsername (), container .getPassword (),
120- command
121+ container .getHost (), container .getInternalPort (),
122+ container .getUsername (), container .getPassword (),
123+ command
121124 );
122125 }
123126
@@ -129,7 +132,7 @@ public <T> T executeCommandDecoded(String command, SslContext sslContext) throws
129132
130133 if (result .getExitCode () != 0 ) {
131134 throw new IllegalStateException (String .format (EXECUTE_COMMAND_ERROR_TEMPLATE ,
132- command , result .getExitCode (), result .getStderr (), result .getStdout ()));
135+ command , result .getExitCode (), result .getStderr (), result .getStdout ()));
133136 }
134137
135138 return yaml .load (result .getStdout ());
0 commit comments