Skip to content

Commit

Permalink
In instrumentation tests, keep @pm@ incremental backups
Browse files Browse the repository at this point in the history
If we request backup in several chunks, @pm@ gets backed up for each chunk, so due to incremental backups, we need to keep old data when comparing.
  • Loading branch information
grote committed Feb 14, 2024
1 parent b47b4ad commit 840e264
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stevesoltys.seedvault.e2e

import android.content.pm.PackageInfo
import android.os.ParcelFileDescriptor
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
import com.stevesoltys.seedvault.e2e.io.BackupDataInputIntercept
import com.stevesoltys.seedvault.e2e.io.InputStreamIntercept
import com.stevesoltys.seedvault.e2e.screen.impl.BackupScreen
Expand Down Expand Up @@ -119,9 +120,21 @@ internal interface LargeBackupTestBase : LargeTestBase {
coEvery {
spyKVBackup.finishBackup()
} answers {
val oldMap = HashMap<String, String>()
// @pm@ can get backed up multiple times (if we need more than one request)
// so we need to keep the data it backed up before
if (packageName == MAGIC_PACKAGE_MANAGER && backupResult.kv.containsKey(packageName)) {
backupResult.kv[packageName]?.forEach { (key, value) ->
// if a key existing in new data, we use its value from new data, don't override
if (!data.containsKey(key)) oldMap[key] = value
}
}
backupResult.kv[packageName!!] = data
.mapValues { entry -> entry.value.sha256() }
.toMutableMap()
.apply {
putAll(oldMap)
}

packageName = null
data = mutableMapOf()
Expand Down

0 comments on commit 840e264

Please sign in to comment.