Add tests for RustMatrixClient.getDatabaseSizes()
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
9a9e84f6c8
commit
de694cecdb
@@ -19,6 +19,23 @@ class ByteSize internal constructor(val value: Long, val unit: ByteUnit) {
|
||||
if (unit == dest) return value
|
||||
return value shl unit.bitShift shr dest.bitShift
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is ByteSize) return false
|
||||
|
||||
return value == other.value && unit == other.unit
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = value.hashCode()
|
||||
result = 31 * result + unit.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "$value $unit"
|
||||
}
|
||||
}
|
||||
|
||||
val Number.gigaBytes get() = ByteSize(toLong(), ByteUnit.GB)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package io.element.android.libraries.matrix.impl
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.data.bytes
|
||||
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
|
||||
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiClient
|
||||
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiSyncService
|
||||
@@ -34,6 +35,7 @@ import kotlinx.coroutines.test.advanceUntilIdle
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.matrix.rustcomponents.sdk.Client
|
||||
import org.matrix.rustcomponents.sdk.StoreSizes
|
||||
import org.matrix.rustcomponents.sdk.UserProfile
|
||||
import java.io.File
|
||||
|
||||
@@ -98,6 +100,20 @@ class RustMatrixClientTest {
|
||||
client.destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getDatabaseSizes returns the database sizes`() = runTest {
|
||||
val client = createRustMatrixClient(
|
||||
client = FakeFfiClient(getStoreSizesResult = { StoreSizes(null, 10uL, 11uL, 12uL) })
|
||||
)
|
||||
|
||||
client.getDatabaseSizes().getOrThrow().run {
|
||||
assertThat(cryptoStore).isNull()
|
||||
assertThat(stateStore).isEqualTo(10.bytes)
|
||||
assertThat(eventCacheStore).isEqualTo(11.bytes)
|
||||
assertThat(mediaStore).isEqualTo(12.bytes)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestScope.createRustMatrixClient(
|
||||
client: Client = FakeFfiClient(),
|
||||
sessionStore: SessionStore = InMemorySessionStore(
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.matrix.rustcomponents.sdk.RoomDirectorySearch
|
||||
import org.matrix.rustcomponents.sdk.Session
|
||||
import org.matrix.rustcomponents.sdk.SessionVerificationController
|
||||
import org.matrix.rustcomponents.sdk.SpaceService
|
||||
import org.matrix.rustcomponents.sdk.StoreSizes
|
||||
import org.matrix.rustcomponents.sdk.SyncService
|
||||
import org.matrix.rustcomponents.sdk.SyncServiceBuilder
|
||||
import org.matrix.rustcomponents.sdk.TaskHandle
|
||||
@@ -46,6 +47,7 @@ class FakeFfiClient(
|
||||
private val withUtdHook: (UnableToDecryptDelegate) -> Unit = { lambdaError() },
|
||||
private val getProfileResult: (String) -> UserProfile = { UserProfile(userId = userId, displayName = null, avatarUrl = null) },
|
||||
private val homeserverLoginDetailsResult: () -> HomeserverLoginDetails = { lambdaError() },
|
||||
private val getStoreSizesResult: () -> StoreSizes = { lambdaError() },
|
||||
private val closeResult: () -> Unit = {},
|
||||
) : Client(NoHandle) {
|
||||
override fun userId(): String = userId
|
||||
@@ -91,5 +93,9 @@ class FakeFfiClient(
|
||||
|
||||
override suspend fun setMediaRetentionPolicy(policy: MediaRetentionPolicy) {}
|
||||
|
||||
override suspend fun getStoreSizes(): StoreSizes {
|
||||
return getStoreSizesResult()
|
||||
}
|
||||
|
||||
override fun close() = closeResult()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user