Created
December 6, 2022 21:37
-
-
Save oharaandrew314/02105c3c073c5150f65e534ab59ef52e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
testImplementation("com.h2database:h2:2.1.214") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.h2.jdbcx.JdbcDataSource | |
import java.util.UUID | |
import javax.sql.DataSource | |
private fun testDb(): DataSource { | |
val dataSource = JdbcDataSource().apply { | |
setURL("jdbc:h2:mem:${UUID.randomUUID()};MODE=MySQL;DB_CLOSE_DELAY=-1") | |
this.user = "sa" | |
this.password = "" | |
} | |
dataSource.connection.use { conn -> | |
conn.prepareStatement( | |
"CREATE TABLE cats (id CHAR(36) PRIMARY KEY NOT NULL, ownerId CHAR(36) NOT NULL, name TEXT NOT NULL)" | |
).executeUpdate() | |
} | |
return dataSource | |
} | |
class JdbcCatsRepoTest: CatsRepoContract(JdbcCatsRepo(testDb())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment