Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adam): StreamingPackageInstallRequest should return parseable response for errors #117

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
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 @@
}
}

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 @@
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
Loading