Skip to content

Commit

Permalink
feat(adam): StreamingPackageInstallRequest should return parseable re…
Browse files Browse the repository at this point in the history
…sponse for errors
  • Loading branch information
Malinskiy committed Aug 14, 2024
1 parent 6cd8361 commit e67ab9c
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StreamingPackageInstallRequest(
private val reinstall: Boolean,
private val extraArgs: List<String> = emptyList(),
val coroutineContext: CoroutineContext = Dispatchers.IO
) : ComplexRequest<Boolean>() {
) : ComplexRequest<StreamingPackageInstallResult>() {

Check warning on line 49 in adam/src/main/kotlin/com/malinskiy/adam/request/pkg/StreamingPackageInstallRequest.kt

View check run for this annotation

Codecov / codecov/patch

adam/src/main/kotlin/com/malinskiy/adam/request/pkg/StreamingPackageInstallRequest.kt#L49

Added line #L49 was not covered by tests
private val transformer = StringResponseTransformer()

override fun validate(): ValidationResponse {
Expand Down Expand Up @@ -110,7 +110,7 @@ class StreamingPackageInstallRequest(
}
}

override suspend fun readElement(socket: Socket): Boolean {
override suspend fun readElement(socket: Socket): StreamingPackageInstallResult {
AsyncFileReader(pkg, coroutineContext = coroutineContext).use { reader ->
reader.start()
reader.copyTo(socket)
Expand All @@ -119,10 +119,14 @@ class StreamingPackageInstallRequest(
withDefaultBuffer {
socket.copyTo(transformer, this)
}
return transformer.transform().startsWith("Success")
val output = transformer.transform()
val success = output.startsWith("Success")

Check warning on line 123 in adam/src/main/kotlin/com/malinskiy/adam/request/pkg/StreamingPackageInstallRequest.kt

View check run for this annotation

Codecov / codecov/patch

adam/src/main/kotlin/com/malinskiy/adam/request/pkg/StreamingPackageInstallRequest.kt#L122-L123

Added lines #L122 - L123 were not covered by tests
return StreamingPackageInstallResult(output, success)
}

companion object {
val SUPPORTED_EXTENSIONS = setOf("apk", "apex")
}
}

data class StreamingPackageInstallResult(val output: String, val success: Boolean)

Check warning on line 132 in adam/src/main/kotlin/com/malinskiy/adam/request/pkg/StreamingPackageInstallRequest.kt

View check run for this annotation

Codecov / codecov/patch

adam/src/main/kotlin/com/malinskiy/adam/request/pkg/StreamingPackageInstallRequest.kt#L132

Added line #L132 was not covered by tests

0 comments on commit e67ab9c

Please sign in to comment.