Skip to content

Commit

Permalink
test: fix common code sharing in test
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods committed Jan 14, 2025
1 parent ad906f4 commit 5f1dbfd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
25 changes: 22 additions & 3 deletions backup/src/commonTest/kotlin/com/wire/backup/BackupEndToEndTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,26 @@ import com.wire.backup.data.BackupQualifiedId
import com.wire.backup.dump.CommonMPBackupExporter
import com.wire.backup.ingest.BackupImportResult
import kotlinx.coroutines.test.runTest
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertIs

expect class BackupEndToEndTest : BaseBackupEndToEndTest
class BackupEndToEndTest {

interface BaseBackupEndToEndTest {
private val subject = endToEndTestSubjectProvider()

@BeforeTest
fun setup() {
subject.setup()
}

@AfterTest
fun beforeAfter() {
subject.tearDown()
}

@Test
fun givenBackedUpTextMessages_whenRestoring_thenShouldReadTheSameContent() = runTest {
Expand Down Expand Up @@ -80,7 +92,7 @@ interface BaseBackupEndToEndTest {
content = content,
)

val result = exportImportDataTest(BackupQualifiedId("eghyue", "potato"), password) {
val result = subject.exportImportDataTest(BackupQualifiedId("eghyue", "potato"), password) {
add(expectedMessage)
}

Expand All @@ -101,6 +113,13 @@ interface BaseBackupEndToEndTest {
assertEquals(expectedMessage.content, firstMessage.content)
assertContentEquals(arrayOf(expectedMessage), allMessages.toTypedArray())
}
}

expect fun endToEndTestSubjectProvider() : CommonBackupEndToEndTestSubjectProvider

interface CommonBackupEndToEndTestSubjectProvider {
fun setup() {}
fun tearDown() {}

suspend fun exportImportDataTest(
selfUserId: BackupQualifiedId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.wire.backup.ingest.MPBackupImporter
import kotlinx.coroutines.await


actual class BackupEndToEndTest : BaseBackupEndToEndTest {
actual fun endToEndTestSubjectProvider() = object : CommonBackupEndToEndTestSubjectProvider {
override suspend fun exportImportDataTest(
selfUserId: BackupQualifiedId,
passphrase: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ import com.wire.backup.ingest.BackupImportResult
import com.wire.backup.ingest.MPBackupImporter
import okio.FileSystem
import okio.SYSTEM
import kotlin.test.AfterTest
import kotlin.test.BeforeTest

actual class BackupEndToEndTest : BaseBackupEndToEndTest {

actual fun endToEndTestSubjectProvider() = object : CommonBackupEndToEndTestSubjectProvider {
private val workDirPath = FileSystem.SYSTEM_TEMPORARY_DIRECTORY / "kalium-backup-test"
private val zipDirectory = workDirPath / "zip"
private val exportDirectory = workDirPath / "export"

@BeforeTest
@AfterTest
fun setup() {
override fun setup() {
FileSystem.SYSTEM.deleteRecursively(workDirPath)
}

override fun tearDown() {
FileSystem.SYSTEM.deleteRecursively(workDirPath)
}

Expand All @@ -57,4 +56,3 @@ actual class BackupEndToEndTest : BaseBackupEndToEndTest {
return importer.importFromFile(artifactPath, passphrase)
}
}

0 comments on commit 5f1dbfd

Please sign in to comment.