Fix KVRestore spies to use new functions

This commit is contained in:
Steve Soltys 2024-09-25 02:38:12 +00:00 committed by Torsten Grote
parent 42d7747641
commit 315e0736f5
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -14,6 +14,8 @@ import com.stevesoltys.seedvault.e2e.screen.impl.RestoreScreen
import com.stevesoltys.seedvault.transport.restore.FullRestore import com.stevesoltys.seedvault.transport.restore.FullRestore
import com.stevesoltys.seedvault.transport.restore.KVRestore import com.stevesoltys.seedvault.transport.restore.KVRestore
import com.stevesoltys.seedvault.transport.restore.OutputFactory import com.stevesoltys.seedvault.transport.restore.OutputFactory
import io.mockk.Call
import io.mockk.MockKAnswerScope
import io.mockk.clearMocks import io.mockk.clearMocks
import io.mockk.coEvery import io.mockk.coEvery
import io.mockk.every import io.mockk.every
@ -161,14 +163,26 @@ internal interface LargeRestoreTestBase : LargeTestBase {
clearMocks(spyKVRestore) clearMocks(spyKVRestore)
coEvery { fun initializeStateBlock(
spyKVRestore.initializeState(any(), any(), any(), any()) packageInfoIndex: Int
} answers { ): MockKAnswerScope<Unit, Unit>.(Call) -> Unit = {
packageName = arg<PackageInfo>(3).packageName packageName = arg<PackageInfo>(packageInfoIndex).packageName
restoreResult.kv[packageName!!] = mutableMapOf() restoreResult.kv[packageName!!] = mutableMapOf()
callOriginal() callOriginal()
} }
coEvery {
spyKVRestore.initializeState(any(), any(), any(), any())
} answers initializeStateBlock(1)
coEvery {
spyKVRestore.initializeStateV1(any(), any(), any(), any())
} answers initializeStateBlock(2)
coEvery {
spyKVRestore.initializeStateV0(any(), any())
} answers initializeStateBlock(1)
every { every {
spyOutputFactory.getBackupDataOutput(any()) spyOutputFactory.getBackupDataOutput(any())
} answers { } answers {
@ -186,19 +200,31 @@ internal interface LargeRestoreTestBase : LargeTestBase {
clearMocks(spyFullRestore) clearMocks(spyFullRestore)
coEvery { fun initializeStateBlock(
spyFullRestore.initializeState(any(), any(), any()) packageInfoIndex: Int
} answers { ): MockKAnswerScope<Unit, Unit>.(Call) -> Unit = {
packageName?.let { packageName?.let {
restoreResult.full[it] = dataIntercept.toByteArray().sha256() restoreResult.full[it] = dataIntercept.toByteArray().sha256()
} }
packageName = arg<PackageInfo>(3).packageName packageName = arg<PackageInfo>(packageInfoIndex).packageName
dataIntercept = ByteArrayOutputStream() dataIntercept = ByteArrayOutputStream()
callOriginal() callOriginal()
} }
coEvery {
spyFullRestore.initializeState(any(), any(), any())
} answers initializeStateBlock(1)
coEvery {
spyFullRestore.initializeStateV1(any(), any(), any())
} answers initializeStateBlock(2)
coEvery {
spyFullRestore.initializeStateV0(any(), any())
} answers initializeStateBlock(1)
every { every {
spyOutputFactory.getOutputStream(any()) spyOutputFactory.getOutputStream(any())
} answers { } answers {