Skip to content

Commit

Permalink
Moved directories to pull to CommonArgs, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfilipow92 authored and mergify-bot committed Oct 26, 2020
1 parent cdf47b9 commit fb8e99f
Showing 12 changed files with 56 additions and 20 deletions.
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ data class AndroidArgs(
val roboDirectives: List<FlankRoboDirective>,
val roboScript: String?,
val environmentVariables: Map<String, String>, // should not be printed, becuase could contains sensitive informations
val directoriesToPull: List<String>,
val grantPermissions: String?,
val type: Type?,
val scenarioNumbers: List<String>,
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/CommonArgs.kt
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ data class CommonArgs(
override val flakyTestAttempts: Int,
override val clientDetails: Map<String, String>?,
override val networkProfile: String?,
override val directoriesToPull: List<String>,

// flank
override val project: String,
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ fun createAndroidArgs(
otherFiles = gcloud.otherFiles!!.mapValues { (_, path) -> path.normalizeFilePath() },
numUniformShards = gcloud.numUniformShards,
environmentVariables = gcloud.environmentVariables!!,
directoriesToPull = gcloud.directoriesToPull!!,
autoGoogleLogin = gcloud.autoGoogleLogin!!,
additionalApks = gcloud.additionalApks!!.map { it.normalizeFilePath() },
roboScript = gcloud.roboScript?.normalizeFilePath(),
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ fun CommonConfig.createCommonArgs(
flakyTestAttempts = gcloud.flakyTestAttempts!!,
networkProfile = gcloud.networkProfile,
clientDetails = gcloud.clientDetails,

directoriesToPull = gcloud.directoriesToPull!!,
// flank
maxTestShards = flank.maxTestShards!!,
shardTime = flank.shardTime!!,
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/IArgs.kt
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ interface IArgs {
val project: String
val resultsHistoryName: String?
val flakyTestAttempts: Int
val directoriesToPull: List<String>

// FlankYml
val maxTestShards: Int
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ IosArgs
xcode-version: $xcodeVersion
device:${ArgsToString.objectsToString(devices)}
num-flaky-test-attempts: $flakyTestAttempts
directories-to-pull: ${ArgsToString.listToString(directoriesToPull)}
flank:
max-test-shards: $maxTestShards
shard-time: $shardTime
Original file line number Diff line number Diff line change
@@ -109,19 +109,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("type")
var type: String? by data

@set:CommandLine.Option(
names = ["--directories-to-pull"],
split = ",",
description = ["A list of paths that will be copied from the device's " +
"storage to the designated results bucket after the test is complete. These must be absolute paths under " +
"/sdcard or /data/local/tmp (for example, --directories-to-pull /sdcard/tempDir1,/data/local/tmp/tempDir2). " +
"Path names are restricted to the characters a-zA-Z0-9_-./+. The paths /sdcard and /data will be made available " +
"and treated as implicit path substitutions. E.g. if /sdcard on a particular device does not map to external " +
"storage, the system will replace it with the external storage path prefix for that device."]
)
@set:JsonProperty("directories-to-pull")
var directoriesToPull: List<String>? by data

@set:CommandLine.Option(
names = ["--other-files"],
split = ",",
@@ -257,7 +244,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
useOrchestrator = true
environmentVariables = emptyMap()
grantPermissions = FlankDefaults.GRANT_PERMISSIONS_ALL
directoriesToPull = emptyList()
otherFiles = emptyMap()
scenarioNumbers = emptyList()
scenarioLabels = emptyList()
Original file line number Diff line number Diff line change
@@ -120,6 +120,19 @@ data class CommonGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("num-flaky-test-attempts")
var flakyTestAttempts: Int? by data

@set:CommandLine.Option(
names = ["--directories-to-pull"],
split = ",",
description = ["A list of paths that will be copied from the device's " +
"storage to the designated results bucket after the test is complete. These must be absolute paths under " +
"/sdcard or /data/local/tmp (for example, --directories-to-pull /sdcard/tempDir1,/data/local/tmp/tempDir2). " +
"Path names are restricted to the characters a-zA-Z0-9_-./+. The paths /sdcard and /data will be made available " +
"and treated as implicit path substitutions. E.g. if /sdcard on a particular device does not map to external " +
"storage, the system will replace it with the external storage path prefix for that device."]
)
@set:JsonProperty("directories-to-pull")
var directoriesToPull: List<String>? by data

constructor() : this(mutableMapOf<String, Any?>().withDefault { null })

companion object : IYmlKeys {
@@ -143,6 +156,7 @@ data class CommonGcloudConfig @JsonIgnore constructor(
clientDetails = null
networkProfile = null
devices = listOf(defaultDevice(android))
directoriesToPull = emptyList()
}
}
}
4 changes: 4 additions & 0 deletions test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import com.google.api.services.testing.model.ClientInfo
import com.google.api.services.testing.model.EnvironmentMatrix
import com.google.api.services.testing.model.FileReference
import com.google.api.services.testing.model.GoogleCloudStorage
import com.google.api.services.testing.model.IosDeviceFile
import com.google.api.services.testing.model.IosDeviceList
import com.google.api.services.testing.model.IosTestSetup
import com.google.api.services.testing.model.IosXcTest
@@ -62,6 +63,7 @@ object GcIosTestMatrix {

val iOSTestSetup = IosTestSetup()
.setNetworkProfile(args.networkProfile)
.setPullDirectories(args.directoriesToPull.toIosDeviceFiles())

val testTimeoutSeconds = timeoutToSeconds(args.testTimeout)

@@ -91,3 +93,5 @@ object GcIosTestMatrix {
}
}
}

private fun List<String>.toIosDeviceFiles() = map { path -> IosDeviceFile().apply { devicePath = path } }
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ class AndroidRunCommandTest {
assertThat(cmd.config.platform.gcloud.numUniformShards).isNull()
assertThat(cmd.config.platform.gcloud.testRunnerClass).isNull()
assertThat(cmd.config.platform.gcloud.environmentVariables).isNull()
assertThat(cmd.config.platform.gcloud.directoriesToPull).isNull()
assertThat(cmd.config.platform.gcloud.otherFiles).isNull()
assertThat(cmd.config.common.gcloud.devices).isNull()
assertThat(cmd.config.common.gcloud.resultsBucket).isNull()
@@ -98,6 +97,7 @@ class AndroidRunCommandTest {
assertThat(cmd.config.common.flank.filesToDownload).isNull()
assertThat(cmd.config.common.gcloud.resultsDir).isNull()
assertThat(cmd.config.common.gcloud.flakyTestAttempts).isNull()
assertThat(cmd.config.common.gcloud.directoriesToPull).isNull()
assertThat(cmd.config.common.flank.disableSharding).isNull()
assertThat(cmd.config.common.flank.localResultsDir).isNull()
assertThat(cmd.config.common.flank.smartFlankDisableUpload).isNull()
@@ -219,7 +219,7 @@ class AndroidRunCommandTest {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--directories-to-pull=a,b")

assertThat(cmd.config.platform.gcloud.directoriesToPull).hasSize(2)
assertThat(cmd.config.common.gcloud.directoriesToPull).hasSize(2)
}

@Test
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@ class IosRunCommandTest {
assertThat(cmd.config.common.gcloud.devices).isNull()
assertThat(cmd.config.common.gcloud.resultsDir).isNull()
assertThat(cmd.config.common.gcloud.flakyTestAttempts).isNull()
assertThat(cmd.config.common.gcloud.directoriesToPull).isNull()
assertThat(cmd.config.common.flank.localResultsDir).isNull()
assertThat(cmd.config.common.flank.smartFlankDisableUpload).isNull()
assertThat(cmd.config.common.flank.smartFlankGcsPath).isNull()
30 changes: 30 additions & 0 deletions test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt
Original file line number Diff line number Diff line change
@@ -11,8 +11,10 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.unmockkAll
import org.junit.After
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import java.io.StringReader

@RunWith(FlankTestRunner::class)
class GcIosTestMatrixTest {
@@ -73,4 +75,32 @@ class GcIosTestMatrixTest {
toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs)
)
}

@Test
fun `should fill directoriesToPull`() {
val iosArgs = IosArgs.load(StringReader("""
gcloud:
test: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/earlgrey_example.zip
xctestrun-file: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos13.4-arm64e.xctestrun
results-dir: test_dir
directories-to-pull:
- test/test/test
""".trimIndent()))

val expected = listOf("test/test/test")
Assert.assertEquals(expected, iosArgs.directoriesToPull)
}

@Test
fun `should not fill directoriesToPull`() {
val iosArgs = IosArgs.load(StringReader("""
gcloud:
test: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/earlgrey_example.zip
xctestrun-file: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos13.4-arm64e.xctestrun
results-dir: test_dir
""".trimIndent()))

val expected = emptyList<String>()
Assert.assertEquals(expected, iosArgs.directoriesToPull)
}
}

0 comments on commit fb8e99f

Please sign in to comment.