Skip to content

Commit

Permalink
Merge pull request #89 from Malinskiy/feature/test-stub-for-split-apk
Browse files Browse the repository at this point in the history
feat(adam): enhance test stub session to support exec
  • Loading branch information
Malinskiy committed Oct 18, 2022
2 parents 2aa3a7a + 03fcc7e commit 35385d3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
@@ -1,5 +1,5 @@
object Versions {
val adam = System.getenv("GIT_TAG_NAME") ?: "0.4.5"
val adam = System.getenv("GIT_TAG_NAME") ?: "0.4.7"
val kotlin = "1.6.21"
val coroutines = "1.6.4"
val coroutinesDebug = coroutines
Expand Down
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2021 Anton Malinskiy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.malinskiy.adam.server.stub.dsl

import java.io.File

class ExecSubSession(private val session: Session) {
suspend fun accept(): ExecSubSession {
session.respondOkay()
return this
}

suspend fun respond(stdout: String): ExecSubSession {
session.respondShellV1(stdout)
return this
}

suspend fun receiveFile(fixture: File): ExecSubSession {
session.expectBytesAsFile(fixture)
return this
}

suspend fun reject(message: String) {
session.respondTransport(false, message)
}
}
Expand Up @@ -39,6 +39,12 @@ class Session(val input: ServerReadChannel, val output: ServerWriteChannel) {
return ShellV1SubSession(session = this)
}

suspend fun expectExec(expected: () -> String): ExecSubSession {
val transportCmd = input.receiveCommand()
assertThat(transportCmd).isEqualTo("exec:${expected()}")
return ExecSubSession(session = this)
}

suspend fun respondTransport(success: Boolean, message: String? = null) {
output.respond(
when (success) {
Expand Down Expand Up @@ -290,6 +296,11 @@ class Session(val input: ServerReadChannel, val output: ServerWriteChannel) {
return input.receiveBytes(size)
}

suspend fun expectBytesAsFile(expected: File) {
val actual = receiveBytes(expected.length().toInt())
assertThat(actual).isEqualTo(expected.readBytes())
}

suspend fun expectAdbServerVersion(): GetAdbServerSubSession {
expectCmd { "host:version" }
return GetAdbServerSubSession(this)
Expand Down

0 comments on commit 35385d3

Please sign in to comment.