|
|
|
|
|
by quicksilver03
864 days ago
|
|
You have just described Testcontainers [1] , and if you are a Java developer you may want to look into Testcontainers for Java [2]. For example, in one of my projects I use TestNG to instantiate a MariaDB container, run the Flyway migrations on it and then populating the tables with the test data: mAPIDBContainer = new MariaDBContainer<>(DockerImageName.parse(MARIADB_CONTAINER_TAG))
.withDatabaseName("apidb")
.withPassword("password")
.withNetwork(containerNetwork)
.withNetworkAliases("apidb")
.withExposedPorts(3306);
mAPIDBContainer.start();
Flyway flyway = Flyway.configure()
.dataSource(mAPIDBContainer.getJdbcUrl(), mAPIDBContainer.getUsername(), mAPIDBContainer.getPassword())
.encoding("UTF-8")
.locations("classpath:apidb/migrations")
.load();
flyway.migrate();
ScriptUtils.runInitScript(new JdbcDatabaseDelegate(mAPIDBContainer, ""), "sql/apidb/apidb-test-data.sql");
[1] https://testcontainers.com/
[2] https://java.testcontainers.org/ |
|