2727import com .fasterxml .jackson .databind .JsonNode ;
2828import com .google .common .collect .ImmutableMap ;
2929import io .airbyte .commons .json .Jsons ;
30- import io .airbyte .commons .resources .MoreResources ;
3130import io .airbyte .db .Database ;
3231import io .airbyte .db .Databases ;
3332import io .airbyte .integrations .source .jdbc .AbstractJdbcSource ;
3433import io .airbyte .integrations .source .jdbc .test .JdbcSourceStandardTest ;
34+ import java .sql .Connection ;
35+ import java .sql .DriverManager ;
36+ import java .sql .SQLException ;
3537import org .apache .commons .lang3 .RandomStringUtils ;
3638import org .jooq .SQLDialect ;
3739import org .junit .jupiter .api .AfterAll ;
3840import org .junit .jupiter .api .AfterEach ;
3941import org .junit .jupiter .api .BeforeAll ;
4042import org .junit .jupiter .api .BeforeEach ;
43+ import org .slf4j .Logger ;
44+ import org .slf4j .LoggerFactory ;
4145import org .testcontainers .containers .MySQLContainer ;
4246
4347class MySqlJdbcStandardTest extends JdbcSourceStandardTest {
4448
49+ private static final Logger LOGGER = LoggerFactory .getLogger (MySqlJdbcStandardTest .class );
50+
4551 private static final String TEST_USER = "test" ;
4652 private static final String TEST_PASSWORD = "test" ;
4753 private static MySQLContainer <?> container ;
@@ -50,13 +56,15 @@ class MySqlJdbcStandardTest extends JdbcSourceStandardTest {
5056 private Database database ;
5157
5258 @ BeforeAll
53- static void init () {
54- // test containers withInitScript only accepts scripts that are mounted as resources.
55- MoreResources . writeResource ( "init.sql" ,
56- "CREATE USER '" + TEST_USER + "'@'%' IDENTIFIED BY '" + TEST_PASSWORD + "'; \n "
57- + "GRANT ALL PRIVILEGES ON *.* TO '" + TEST_USER + "'@'%'; \n " );
58- container = new MySQLContainer <>( "mysql:8.0" ). withInitScript ( "init.sql" ). withUsername ( "root" ). withPassword ( "" );
59+ static void init () throws SQLException {
60+ container = new MySQLContainer <>( "mysql:8.0" )
61+ . withUsername ( TEST_USER )
62+ . withPassword ( TEST_PASSWORD )
63+ . withEnv ( "MYSQL_ROOT_HOST" , "%" )
64+ . withEnv ( "MYSQL_ROOT_PASSWORD" , TEST_PASSWORD );
5965 container .start ();
66+ Connection connection = DriverManager .getConnection (container .getJdbcUrl (), "root" , TEST_PASSWORD );
67+ connection .createStatement ().execute ("GRANT ALL PRIVILEGES ON *.* TO '" + TEST_USER + "'@'%';\n " );
6068 }
6169
6270 @ BeforeEach
@@ -76,6 +84,7 @@ public void setup() throws Exception {
7684 config .get ("host" ).asText (),
7785 config .get ("port" ).asText ()),
7886 MySqlSource .DRIVER_CLASS ,
87+
7988 SQLDialect .MYSQL );
8089
8190 database .query (ctx -> {
@@ -84,6 +93,8 @@ public void setup() throws Exception {
8493 });
8594 database .close ();
8695
96+ container .getEnv ().forEach (
97+ s -> LOGGER .info ("Env: {}" , s ));
8798 super .setup ();
8899 }
89100
0 commit comments