mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: local builds reuse the add-on packs a CI build installed (#1265)
This commit is contained in:
1 parent
7bb66de192
commit
d70f5f0636
2 files changed
+74
-4
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import java.io.File
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class AddonPackTest {
|
||||
private val context: Context = ApplicationProvider.getApplicationContext()
|
||||
private val root get() = File(context.filesDir, "addons/sample")
|
||||
|
||||
@Before fun clean() {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
|
||||
private fun installed(version: String, complete: Boolean = true, modified: Long = 1_000L): File =
|
||||
File(root, version).apply {
|
||||
mkdirs()
|
||||
File(this, "tool").writeText("x")
|
||||
if (complete) File(this, AddonPack.COMPLETE).writeText(version)
|
||||
setLastModified(modified)
|
||||
}
|
||||
|
||||
@Test fun unpinnedLocalBuildReusesTheNewestCompletePack() {
|
||||
installed("a".repeat(64), modified = 1_000L)
|
||||
installed("b".repeat(64), modified = 2_000L)
|
||||
installed("c".repeat(64), complete = false, modified = 3_000L)
|
||||
val pack = AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = true)
|
||||
|
||||
assertTrue(pack.installed(context))
|
||||
assertEquals("b".repeat(64), pack.dir(context).name)
|
||||
}
|
||||
|
||||
@Test fun unpinnedLocalBuildWithNothingInstalledHasNoPack() {
|
||||
assertFalse(AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = true).installed(context))
|
||||
}
|
||||
|
||||
@Test fun pinnedBuildIgnoresOtherInstalledVersions() {
|
||||
installed("b".repeat(64))
|
||||
val pack = AddonPack("sample", "a".repeat(64), 1L, listOf("tool"))
|
||||
|
||||
assertFalse(pack.installed(context))
|
||||
assertEquals("a".repeat(64), pack.dir(context).name)
|
||||
}
|
||||
|
||||
@Test fun ciBuildWithoutAPinNeverReuses() {
|
||||
installed("b".repeat(64))
|
||||
assertFalse(AddonPack("sample", "", 0L, listOf("tool"), reuseDeviceCopy = false).installed(context))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user