Refactor: Move InMemorySessionStore to test module (#5252)
* Refactor: Move InMemorySessionStore to test module - Delete `libraries/session-storage/impl-memory` module - Move `InMemorySessionStore.kt` to `libraries/session-storage/test` * Cleanup tests. * Fix error.
This commit is contained in:
commit
00ca73f342
20 changed files with 144 additions and 188 deletions
|
|
@ -36,7 +36,6 @@ dependencies {
|
|||
testImplementation(libs.test.truth)
|
||||
testImplementation(libs.test.turbine)
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
testImplementation(projects.libraries.sessionStorage.implMemory)
|
||||
testImplementation(projects.libraries.sessionStorage.test)
|
||||
testImplementation(projects.libraries.preferences.test)
|
||||
testImplementation(projects.tests.testutils)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ package io.element.android.features.migration.impl.migrations
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.preferences.test.FakeSessionPreferencesStoreFactory
|
||||
import io.element.android.libraries.preferences.test.InMemorySessionPreferencesStore
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
|
@ -20,12 +20,12 @@ import org.junit.Test
|
|||
class AppMigration02Test {
|
||||
@Test
|
||||
fun `test migration`() = runTest {
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
updateData(aSessionData())
|
||||
}
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData()),
|
||||
)
|
||||
val sessionPreferencesStore = InMemorySessionPreferencesStore(isSessionVerificationSkipped = false)
|
||||
val sessionPreferencesStoreFactory = FakeSessionPreferencesStoreFactory(
|
||||
getLambda = lambdaRecorder { _, _, -> sessionPreferencesStore },
|
||||
getLambda = lambdaRecorder { _, _ -> sessionPreferencesStore },
|
||||
removeLambda = lambdaRecorder { _ -> }
|
||||
)
|
||||
val migration = AppMigration02(sessionStore = sessionStore, sessionPreferenceStoreFactory = sessionPreferencesStoreFactory)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ package io.element.android.features.migration.impl.migrations
|
|||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
|
@ -18,14 +18,14 @@ import java.io.File
|
|||
class AppMigration05Test {
|
||||
@Test
|
||||
fun `empty session path should be set to an expected path`() = runTest {
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
updateData(
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(
|
||||
aSessionData(
|
||||
sessionId = A_SESSION_ID.value,
|
||||
sessionPath = "",
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path"))
|
||||
migration.migrate()
|
||||
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
|
||||
|
|
@ -34,14 +34,14 @@ class AppMigration05Test {
|
|||
|
||||
@Test
|
||||
fun `non empty session path should not be impacted by the migration`() = runTest {
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
updateData(
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(
|
||||
aSessionData(
|
||||
sessionId = A_SESSION_ID.value,
|
||||
sessionPath = "/a/path/existing",
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path"))
|
||||
migration.migrate()
|
||||
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ package io.element.android.features.migration.impl.migrations
|
|||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
|
@ -18,15 +18,15 @@ import java.io.File
|
|||
class AppMigration06Test {
|
||||
@Test
|
||||
fun `empty cache path should be set to an expected path`() = runTest {
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
updateData(
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(
|
||||
aSessionData(
|
||||
sessionId = A_SESSION_ID.value,
|
||||
sessionPath = "/a/path/to/a/session/AN_ID",
|
||||
cachePath = "",
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
val migration = AppMigration06(sessionStore = sessionStore, cacheDirectory = File("/a/path/cache"))
|
||||
migration.migrate()
|
||||
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
|
||||
|
|
@ -35,14 +35,14 @@ class AppMigration06Test {
|
|||
|
||||
@Test
|
||||
fun `non empty cache path should not be impacted by the migration`() = runTest {
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
updateData(
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(
|
||||
aSessionData(
|
||||
sessionId = A_SESSION_ID.value,
|
||||
cachePath = "/a/path/existing",
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
val migration = AppMigration05(sessionStore = sessionStore, baseDirectory = File("/a/path/cache"))
|
||||
migration.migrate()
|
||||
val storedData = sessionStore.getSession(A_SESSION_ID.value)!!
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ dependencies {
|
|||
testImplementation(libs.test.mockk)
|
||||
testImplementation(projects.features.enterprise.test)
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
testImplementation(projects.libraries.sessionStorage.implMemory)
|
||||
testImplementation(projects.libraries.sessionStorage.test)
|
||||
testImplementation(projects.features.rageshake.test)
|
||||
testImplementation(projects.libraries.preferences.test)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
|
|||
import io.element.android.libraries.matrix.test.tracing.FakeTracingService
|
||||
import io.element.android.libraries.network.useragent.DefaultUserAgentProvider
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||
|
|
@ -104,9 +104,9 @@ class DefaultBugReporterTest {
|
|||
)
|
||||
server.start()
|
||||
|
||||
val mockSessionStore = InMemorySessionStore().apply {
|
||||
storeData(aSessionData(sessionId = "@foo:example.com", deviceId = "ABCDEFGH"))
|
||||
}
|
||||
val mockSessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData(sessionId = "@foo:example.com", deviceId = "ABCDEFGH"))
|
||||
)
|
||||
|
||||
val fakeEncryptionService = FakeEncryptionService()
|
||||
val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService)
|
||||
|
|
@ -165,9 +165,9 @@ class DefaultBugReporterTest {
|
|||
)
|
||||
server.start()
|
||||
|
||||
val mockSessionStore = InMemorySessionStore().apply {
|
||||
storeData(aSessionData("@foo:example.com", "ABCDEFGH"))
|
||||
}
|
||||
val mockSessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData("@foo:example.com", "ABCDEFGH"))
|
||||
)
|
||||
|
||||
val fakeEncryptionService = FakeEncryptionService()
|
||||
val matrixClient = FakeMatrixClient(encryptionService = fakeEncryptionService)
|
||||
|
|
@ -308,9 +308,9 @@ class DefaultBugReporterTest {
|
|||
fun `the log directory is initialized using the last session store data`() = runTest {
|
||||
val sut = createDefaultBugReporter(
|
||||
buildMeta = aBuildMeta(isEnterpriseBuild = true),
|
||||
sessionStore = InMemorySessionStore().apply {
|
||||
storeData(aSessionData(sessionId = "@alice:domain.com"))
|
||||
}
|
||||
sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData(sessionId = "@alice:domain.com"))
|
||||
)
|
||||
)
|
||||
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs/domain.com")
|
||||
}
|
||||
|
|
@ -318,9 +318,9 @@ class DefaultBugReporterTest {
|
|||
@Test
|
||||
fun `foss build - the log directory is initialized to the root log directory`() = runTest {
|
||||
val sut = createDefaultBugReporter(
|
||||
sessionStore = InMemorySessionStore().apply {
|
||||
storeData(aSessionData(sessionId = "@alice:domain.com"))
|
||||
}
|
||||
sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData(sessionId = "@alice:domain.com"))
|
||||
)
|
||||
)
|
||||
assertThat(sut.logDirectory().absolutePath).endsWith("/cache/logs")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ dependencies {
|
|||
testImplementation(libs.test.truth)
|
||||
testImplementation(libs.test.turbine)
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
testImplementation(projects.libraries.sessionStorage.implMemory)
|
||||
testImplementation(projects.libraries.sessionStorage.test)
|
||||
testImplementation(projects.tests.testutils)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import io.element.android.libraries.matrix.api.core.SessionId
|
|||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||
import io.element.android.libraries.sessionstorage.impl.memory.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
|
@ -31,9 +31,9 @@ class SignedOutPresenterTest {
|
|||
@Test
|
||||
fun `present - initial state`() = runTest {
|
||||
val aSessionData = aSessionData()
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
storeData(aSessionData)
|
||||
}
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData)
|
||||
)
|
||||
val presenter = createSignedOutPresenter(sessionStore = sessionStore)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
|
|
@ -48,9 +48,9 @@ class SignedOutPresenterTest {
|
|||
@Test
|
||||
fun `present - sign in again`() = runTest {
|
||||
val aSessionData = aSessionData()
|
||||
val sessionStore = InMemorySessionStore().apply {
|
||||
storeData(aSessionData)
|
||||
}
|
||||
val sessionStore = InMemorySessionStore(
|
||||
initialList = listOf(aSessionData)
|
||||
)
|
||||
val presenter = createSignedOutPresenter(sessionStore = sessionStore)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue