mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 18:07:03 +05:30
refactor(database): de-dupe test database setup
This commit is contained in:
parent
cbf0707aa6
commit
1394bc74c4
3 changed files with 24 additions and 26 deletions
|
@ -6,11 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package dev.msfjarvis.claw.database.local
|
package dev.msfjarvis.claw.database.local
|
||||||
|
|
||||||
import app.cash.sqldelight.adapter.primitive.IntColumnAdapter
|
|
||||||
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
|
||||||
import dev.msfjarvis.claw.database.model.CSVAdapter
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -20,15 +16,7 @@ class PostCommentsQueriesTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
val driver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
|
postQueries = setupDatabase().postCommentsQueries
|
||||||
LobstersDatabase.Schema.create(driver)
|
|
||||||
val database =
|
|
||||||
LobstersDatabase(
|
|
||||||
driver,
|
|
||||||
PostComments.Adapter(CSVAdapter()),
|
|
||||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
|
||||||
)
|
|
||||||
postQueries = database.postCommentsQueries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -6,11 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package dev.msfjarvis.claw.database.local
|
package dev.msfjarvis.claw.database.local
|
||||||
|
|
||||||
import app.cash.sqldelight.adapter.primitive.IntColumnAdapter
|
|
||||||
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
|
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
|
||||||
import dev.msfjarvis.claw.database.model.CSVAdapter
|
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
@ -19,15 +15,7 @@ class SavedPostQueriesTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
val driver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
|
postQueries = setupDatabase().savedPostQueries
|
||||||
LobstersDatabase.Schema.create(driver)
|
|
||||||
val database =
|
|
||||||
LobstersDatabase(
|
|
||||||
driver,
|
|
||||||
PostComments.Adapter(CSVAdapter()),
|
|
||||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
|
||||||
)
|
|
||||||
postQueries = database.savedPostQueries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Harsh Shandilya.
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
package dev.msfjarvis.claw.database.local
|
||||||
|
|
||||||
|
import app.cash.sqldelight.adapter.primitive.IntColumnAdapter
|
||||||
|
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
|
||||||
|
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||||
|
import dev.msfjarvis.claw.database.model.CSVAdapter
|
||||||
|
|
||||||
|
fun setupDatabase(): LobstersDatabase {
|
||||||
|
val driver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
|
||||||
|
LobstersDatabase.Schema.create(driver)
|
||||||
|
return LobstersDatabase(
|
||||||
|
driver,
|
||||||
|
PostComments.Adapter(CSVAdapter()),
|
||||||
|
SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
||||||
|
)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue