Skip to content

Commit

Permalink
Add --keep-file-path (#615)
Browse files Browse the repository at this point in the history
* Add preserveOriginalPath toggle

Update readme with new toggle

add toggle to android flank yml

Add cli command and tests for preserve-original-path

* Simplify filePathName

Rename preserveOriginalPath to keepFilePath

Update release_notes.md
  • Loading branch information
tahirhajizada authored and bootstraponline committed Nov 1, 2019
1 parent 5448349 commit 4f0d4a3
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ flank:

## Local folder to store the test result. Folder is DELETED before each run to ensure only artifacts from the new run are saved.
# local-result-dir: flank

## Keeps the full path of downloaded files. Required when file names are not unique.
## Default: false
# keep-file-path: false

## Include additional app/test apk pairs in the run. If app is omitted, then the top level app is used for that pair.
# additional-app-test-apks:
Expand Down
2 changes: 1 addition & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## next (unreleased)

- [#612](https://github.com/TestArmada/flank/pull/612) Print HtmlErrorReport location. ([bootstraponline](https://github.com/bootstraponline))
-
- [#615](https://github.com/TestArmada/flank/pull/615) Add `--keep-file-path` for Android when downloading assets from Google Cloud Storage. ([tahirhajizada](https://github.com/tahirhajizada))

## v8.0.1

Expand Down
4 changes: 4 additions & 0 deletions test_runner/flank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ flank:
## Local folder to store the test result. Folder is DELETED before each run to ensure only artifacts from the new run are saved.
# local-result-dir: flank

## Downloaded files preserves the original path of file. Required when file names are not unique.
## Default: false
# keep-file-path: false

## Include additional app/test apk pairs in the run. If app is omitted, then the top level app is used for that pair.
# additional-app-test-apks:
# - app: ../test_app/apks/app-debug.apk
Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class AndroidArgs(

private val androidFlank = androidFlankYml.flank
val additionalAppTestApks = cli?.additionalAppTestApks ?: androidFlank.additionalAppTestApks
val keepFilePath = cli?.keepFilePath ?: androidFlank.keepFilePath

init {
resultsBucket = createGcsBucket(project, cli?.resultsBucket ?: gcloud.resultsBucket)
Expand Down Expand Up @@ -149,6 +150,7 @@ ${listToString(testTargetsAlwaysRun)}
project: $project
local-result-dir: $localResultDir
# Android Flank Yml
keep-file-path: $keepFilePath
additional-app-test-apks:
${apksToString(additionalAppTestApks)}
""".trimIndent()
Expand Down
7 changes: 5 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/yml/AndroidFlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ data class AppTestPair(
@JsonIgnoreProperties(ignoreUnknown = true)
class AndroidFlankYmlParams(
@field:JsonProperty("additional-app-test-apks")
val additionalAppTestApks: List<AppTestPair> = emptyList()
val additionalAppTestApks: List<AppTestPair> = emptyList(),

@field:JsonProperty("keep-file-path")
val keepFilePath: Boolean = false
) {
companion object : IYmlKeys {
override val keys = listOf("additional-app-test-apks")
override val keys = listOf("additional-app-test-apks", "keep-file-path")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,11 @@ class AndroidRunCommand : Runnable {
}

var additionalAppTestApks: MutableList<AppTestPair>? = null

@Option(
names = ["--keep-file-path"],
description = ["Keeps the full path of downloaded files. " +
"Required when file names are not unique."]
)
var keepFilePath: Boolean? = null
}
10 changes: 8 additions & 2 deletions test_runner/src/main/kotlin/ftl/run/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,15 @@ object TestRunner {

// Store downloaded artifacts at device root.
return if (args.useLocalResultDir()) {
Paths.get(localDir, p.shardName, p.deviceName, p.fileName)
if (args is AndroidArgs && args.keepFilePath)
Paths.get(localDir, p.shardName, p.deviceName, p.filePathName, p.fileName)
else
Paths.get(localDir, p.shardName, p.deviceName, p.fileName)
} else {
Paths.get(localDir, p.objName, p.shardName, p.deviceName, p.fileName)
if (args is AndroidArgs && args.keepFilePath)
Paths.get(localDir, p.objName, p.shardName, p.deviceName, p.filePathName, p.fileName)
else
Paths.get(localDir, p.objName, p.shardName, p.deviceName, p.fileName)
}
}

Expand Down
9 changes: 7 additions & 2 deletions test_runner/src/main/kotlin/ftl/util/ObjPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ data class ObjPath(
val fileName: String,
val objName: String,
val shardName: String,
val deviceName: String
val deviceName: String,
val filePathName: String
) {
companion object {
fun parse(path: String): ObjPath {
Expand All @@ -16,12 +17,16 @@ data class ObjPath(
val objName = parsed.getName(0).toString()
val shardName = parsed.getName(1).toString()
val deviceName = parsed.getName(2).toString()
val filePathName = if (parsed.nameCount > 4) {
parsed.parent.drop(3).joinToString("/")
} else { "" }

return ObjPath(
fileName = fileName,
objName = objName,
shardName = shardName,
deviceName = deviceName
deviceName = deviceName,
filePathName = filePathName
)
}
}
Expand Down
20 changes: 20 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AndroidArgsTest {
- class example.Test#grantPermission
- class example.Test#grantPermission2
disable-sharding: true
keep-file-path: true
additional-app-test-apks:
- app: foo
test: bar
Expand Down Expand Up @@ -249,6 +250,7 @@ AndroidArgs
project: projectFoo
local-result-dir: results
# Android Flank Yml
keep-file-path: true
additional-app-test-apks:
- app: foo
test: bar
Expand Down Expand Up @@ -916,4 +918,22 @@ AndroidArgs
assertThat(androidArgs.additionalAppTestApks).isEqualTo(
listOf(AppTestPair("a", "b")))
}

@Test
fun `cli keep-file-path`() {
val cli = AndroidRunCommand()
CommandLine(cli).parseArgs("--keep-file-path=true")

val yaml = """
gcloud:
app: $appApk
test: $testApk
flank:
keep-file-path: false
"""
assertThat(AndroidArgs.load(yaml).keepFilePath).isEqualTo(false)

val androidArgs = AndroidArgs.load(yaml, cli)
assertThat(androidArgs.keepFilePath).isEqualTo(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class AndroidRunCommandTest {
assertThat(cmd.smartFlankDisableUpload).isNull()
assertThat(cmd.smartFlankGcsPath).isNull()
assertThat(cmd.additionalAppTestApks).isNull()
assertThat(cmd.keepFilePath).isNull()
}

@Test
Expand Down Expand Up @@ -352,6 +353,14 @@ class AndroidRunCommandTest {
assertThat(cmd.smartFlankGcsPath).isEqualTo("foo")
}

@Test
fun `keepFilePath parse`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--keep-file-path=true")

assertThat(cmd.keepFilePath).isEqualTo(true)
}

@Test
fun `additionalAppTestApks parse`() {
val cmd = AndroidRunCommand()
Expand Down
45 changes: 43 additions & 2 deletions test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestRunnerTest {
private val args = mock(AndroidArgs::class.java)

@Test
fun `Verify getDownloadPath localResultDir false`() {
fun `Verify getDownloadPath localResultDir false and keepFilePath false`() {
val parsed = ObjPath.parse(gcsPath)

`when`(args.localResultDir).thenReturn(localResultDir)
Expand All @@ -42,7 +42,7 @@ class TestRunnerTest {
}

@Test
fun `Verify getDownloadPath localResultDir true`() {
fun `Verify getDownloadPath localResultDir true and keepFilePath false`() {
val parsed = ObjPath.parse(gcsPath)

`when`(args.localResultDir).thenReturn(localResultDir)
Expand All @@ -59,6 +59,47 @@ class TestRunnerTest {
)
}

@Test
fun `Verify getDownloadPath localResultDir true and keepFilePath true`() {
val parsed = ObjPath.parse(gcsPath)

`when`(args.localResultDir).thenReturn(localResultDir)
`when`(args.useLocalResultDir()).thenReturn(true)
`when`(args.keepFilePath).thenReturn(true)

val downloadFile = TestRunner.getDownloadPath(args, gcsPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.shardName,
parsed.deviceName,
parsed.filePathName,
parsed.fileName
)
)
}

@Test
fun `Verify getDownloadPath localResultDir false and keepFilePath true`() {
val parsed = ObjPath.parse(gcsPath)

`when`(args.localResultDir).thenReturn(localResultDir)
`when`(args.useLocalResultDir()).thenReturn(false)
`when`(args.keepFilePath).thenReturn(true)

val downloadFile = TestRunner.getDownloadPath(args, gcsPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.objName,
parsed.shardName,
parsed.deviceName,
parsed.filePathName,
parsed.fileName
)
)
}

@Test
fun `mockedAndroidTestRun local`() {
val localConfig = AndroidArgs.load(Paths.get("src/test/kotlin/ftl/fixtures/flank.local.yml"))
Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/test/kotlin/ftl/util/ObjPathTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class ObjPathTest {

@Test
fun parse() {
val path = "2019-03-22_15-39-20.400000_ESdl/shard_0/NexusLowRes-28-en-portrait/b.txt"
val path = "2019-03-22_15-39-20.400000_ESdl/shard_0/NexusLowRes-28-en-portrait/com/package/name/b.txt"
val parsed = ObjPath.parse(path)

assertThat(parsed.objName).isEqualTo("2019-03-22_15-39-20.400000_ESdl")
assertThat(parsed.fileName).isEqualTo("b.txt")
assertThat(parsed.shardName).isEqualTo("shard_0")
assertThat(parsed.deviceName).isEqualTo("NexusLowRes-28-en-portrait")
assertThat(parsed.filePathName).isEqualTo("com/package/name")
}
}

0 comments on commit 4f0d4a3

Please sign in to comment.