Skip to content

Commit

Permalink
fix jvm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Dec 3, 2024
1 parent 8c19504 commit b2ce0f5
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.wire.kalium.persistence.db.PlatformDatabaseData
import com.wire.kalium.persistence.db.globalDatabaseProvider
import com.wire.kalium.persistence.util.FileNameUtil
import com.wire.kalium.util.KaliumDispatcherImpl
import kotlinx.coroutines.test.TestDispatcher

actual abstract class GlobalDBBaseTest {

Expand All @@ -35,7 +34,7 @@ actual abstract class GlobalDBBaseTest {
context.deleteDatabase(FileNameUtil.globalDBName())
}

actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder = globalDatabaseProvider(
actual fun createDatabase(): GlobalDatabaseBuilder = globalDatabaseProvider(
platformDatabaseData = PlatformDatabaseData(ApplicationProvider.getApplicationContext()),
queriesContext = KaliumDispatcherImpl.unconfined,
passphrase = GlobalDatabaseSecret("test_db_secret".toByteArray()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ actual abstract class GlobalDBBaseTest {
TODO("Not yet implemented")
}

actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder {
actual fun createDatabase(): GlobalDatabaseBuilder {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.wire.kalium.persistence.db.StorageData
import com.wire.kalium.persistence.db.globalDatabaseProvider
import com.wire.kalium.persistence.util.FileNameUtil
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestDispatcher
import platform.Foundation.NSCachesDirectory
import platform.Foundation.NSFileManager
import platform.Foundation.NSUserDomainMask
Expand All @@ -38,7 +37,7 @@ actual abstract class GlobalDBBaseTest {
deleteDatabase(FileNameUtil.globalDBName(), storePath)
}

actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder {
actual fun createDatabase(): GlobalDatabaseBuilder {
return globalDatabaseProvider(
PlatformDatabaseData(StorageData.FileBacked(storePath)), StandardTestDispatcher(), null, false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ value class GlobalDatabaseSecret(val value: ByteArray)
class GlobalDatabaseBuilder internal constructor(
private val sqlDriver: SqlDriver,
private val platformDatabaseData: PlatformDatabaseData,
protected val queriesContext: CoroutineContext = KaliumDispatcherImpl.io
private val queriesContext: CoroutineContext = KaliumDispatcherImpl.io
) {

internal val database: GlobalDatabase = GlobalDatabase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package com.wire.kalium.persistence

import com.wire.kalium.persistence.db.GlobalDatabaseBuilder
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestDispatcher

expect abstract class GlobalDBBaseTest() {
fun deleteDatabase()
fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder
fun createDatabase(): GlobalDatabaseBuilder
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,15 @@ class ServerConfigurationDAOTest : GlobalDBBaseTest() {
private val config3 = newServerConfig(id = 3)

lateinit var globalDatabaseBuilder: GlobalDatabaseBuilder
private val dispatcher: TestDispatcher = StandardTestDispatcher()

@BeforeTest
fun setup() {
Dispatchers.setMain(dispatcher)
globalDatabaseBuilder = createDatabase(dispatcher)
globalDatabaseBuilder = createDatabase()
}

@AfterTest
fun nuke() {
deleteDatabase()
Dispatchers.resetMain()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ import com.wire.kalium.persistence.db.GlobalDatabaseBuilder
import com.wire.kalium.persistence.model.LogoutReason
import com.wire.kalium.persistence.model.ServerConfigEntity
import com.wire.kalium.persistence.model.SsoIdEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestCoroutineScheduler
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -42,12 +47,11 @@ import kotlin.test.assertNull
class AccountsDAOTest : GlobalDBBaseTest() {

lateinit var globalDatabaseBuilder: GlobalDatabaseBuilder
private val dispatcher: TestDispatcher = StandardTestDispatcher()

@BeforeTest
fun setUp() = runTest {
deleteDatabase()
globalDatabaseBuilder = createDatabase(dispatcher)
globalDatabaseBuilder = createDatabase()

with(SERVER_CONFIG) {
globalDatabaseBuilder.serverConfigurationDAO.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
package com.wire.kalium.persistence

import com.wire.kalium.persistence.db.GlobalDatabaseBuilder
import kotlinx.coroutines.test.TestDispatcher

actual abstract class GlobalDBBaseTest {
actual fun deleteDatabase() {
TODO("Not yet implemented")
}

actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder {
actual fun createDatabase(): GlobalDatabaseBuilder {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import kotlinx.coroutines.test.TestDispatcher
import java.nio.file.Files

actual abstract class GlobalDBBaseTest {
private val dispatcher: TestDispatcher = StandardTestDispatcher()
private val databaseFile = Files.createTempDirectory("test-storage").toFile().resolve("test-kalium.db")

actual fun deleteDatabase() {
databaseFile.delete()
}

actual fun createDatabase(dispatcher: TestDispatcher): GlobalDatabaseBuilder {
actual fun createDatabase(): GlobalDatabaseBuilder {
return globalDatabaseProvider(
platformDatabaseData = PlatformDatabaseData(
StorageData.FileBacked(databaseFile)
Expand Down

0 comments on commit b2ce0f5

Please sign in to comment.