mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
test: cover independent agent log exports
This commit is contained in:
1 parent
9f22f63222
commit
285ff7956b
2 files changed
+69
No files matched your search
@@ -0,0 +1,65 @@
|
|||||||
|
package com.droiddeck.launcher.agent
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import com.droiddeck.launcher.session.SessionState
|
||||||
|
import com.droiddeck.launcher.session.installJvmSecureSourceOpener
|
||||||
|
import com.droiddeck.launcher.session.resetSecureSourceOpener
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.Robolectric
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.RuntimeEnvironment
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@Config(sdk = [33], manifest = Config.NONE)
|
||||||
|
class AgentLogExportTest {
|
||||||
|
private val context get() = RuntimeEnvironment.getApplication()
|
||||||
|
private var previousLogDirectory: File? = null
|
||||||
|
|
||||||
|
@Before fun prepare() {
|
||||||
|
previousLogDirectory = SessionState.logDirectory
|
||||||
|
installJvmSecureSourceOpener()
|
||||||
|
}
|
||||||
|
|
||||||
|
@After fun cleanup() {
|
||||||
|
SessionState.logDirectory = previousLogDirectory
|
||||||
|
resetSecureSourceOpener()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun independentLogRequestsKeepBothExportDirectories() {
|
||||||
|
val session = File(context.cacheDir, "agent-session").apply { mkdirs() }
|
||||||
|
File(session, "session.log").writeText("booted\n")
|
||||||
|
SessionState.logDirectory = session
|
||||||
|
val provider = Robolectric.buildContentProvider(AgentBridgeProvider::class.java).create().get()
|
||||||
|
var firstDir: File? = null
|
||||||
|
var secondDir: File? = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
fun requestLogs() = JSONObject(provider.call("logs", null, Bundle()).getString("json")!!)
|
||||||
|
val first = requestLogs()
|
||||||
|
val second = requestLogs()
|
||||||
|
firstDir = File(first.getString("cleanupDir"))
|
||||||
|
secondDir = File(second.getString("cleanupDir"))
|
||||||
|
val firstZip = File(first.getString("zip"))
|
||||||
|
val secondZip = File(second.getString("zip"))
|
||||||
|
|
||||||
|
assertNotEquals(firstDir, secondDir)
|
||||||
|
assertEquals(firstDir, firstZip.parentFile)
|
||||||
|
assertEquals(secondDir, secondZip.parentFile)
|
||||||
|
assertTrue(firstZip.isFile)
|
||||||
|
assertTrue(secondZip.isFile)
|
||||||
|
} finally {
|
||||||
|
firstDir?.deleteRecursively()
|
||||||
|
secondDir?.deleteRecursively()
|
||||||
|
session.deleteRecursively()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,6 +92,10 @@ Every command writes one JSON object to stdout and its resolved serial to stderr
|
|||||||
success, 2 invalid or rejected command, 3 ADB or device error, 4 session error, 5 timeout, 6
|
success, 2 invalid or rejected command, 3 ADB or device error, 4 session error, 5 timeout, 6
|
||||||
artifact or file error, 7 debugging tools disabled.
|
artifact or file error, 7 debugging tools disabled.
|
||||||
|
|
||||||
|
When upgrading the CLI, use a new destination for the first pull if the old destination contains
|
||||||
|
archives created by an older CLI without a `.droiddeckctl-managed-logs.json` manifest and their
|
||||||
|
filenames overlap. The upgraded CLI refuses to overwrite those files to preserve unrelated data.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
Reference in new issue
Block a user