Skip to content

Commit

Permalink
Refactor and remove ObjPath class
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed May 21, 2020
1 parent a144008 commit 2ace9ac
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object ReportManager {
val objName = matrices.runPath // 2019-03-22_17-20-53.594000_ftrh

// shard location in path changes based on iOS or Android.
val matchResult = Regex("/(shard_\\d+)(-rerun_\\d+)?/").find(xmlFile.toString())
val matchResult = Regex("/.*(shard_\\d+)(-rerun_\\d+)?/").find(xmlFile.toString())
val shardName = matchResult?.value?.removePrefix("/")?.removeSuffix("/") // shard_0 || shard_0-rerun_1
val matrixPath = Paths.get(objName, shardName).toString() // 2019-03-22_17-20-53.594000_ftrh/shard_0

Expand Down
29 changes: 11 additions & 18 deletions test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package ftl.run.common

import com.google.cloud.storage.Storage
import ftl.args.AndroidArgs
import ftl.args.IArgs
import ftl.config.FtlConstants
import ftl.gc.GcStorage
import ftl.json.MatrixMap
import ftl.gc.GcStorage
import ftl.util.Artifacts
import ftl.util.MatrixState
import ftl.util.ObjPath
import java.nio.file.Path
import java.nio.file.Paths
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import java.nio.file.Path
import java.nio.file.Paths

internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = coroutineScope {
println("FetchArtifacts")
Expand Down Expand Up @@ -64,18 +62,13 @@ internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = corouti

internal fun getDownloadPath(args: IArgs, blobPath: String): Path {
val localDir = args.localResultDir
val p = if (args is AndroidArgs)
ObjPath.parse(blobPath) else
ObjPath.legacyParse(blobPath)
val parsed = Paths.get(blobPath)
val objName = if (args.useLocalResultDir()) "" else parsed.getName(0).toString()
// for iOS it is shardName, remove this comment after FTL introduce server side sharding for iOS
val matrixName = parsed.getName(1).toString()
val deviceName = parsed.getName(2).toString()
val filePathName = if (parsed.nameCount > 4 && args.keepFilePath) parsed.parent.drop(3).joinToString("/") else ""
val fileName = parsed.fileName.toString()

// Store downloaded artifacts at device root.
return Paths.get(
localDir,
if (args.useLocalResultDir().not()) p.objName else "",
p.matrixName,
p.shardName,
p.deviceName,
if (args.keepFilePath) p.filePathName else "",
p.fileName
)
return Paths.get("$localDir/$objName/$matrixName/$deviceName/$filePathName/$fileName")
}
59 changes: 0 additions & 59 deletions test_runner/src/main/kotlin/ftl/util/ObjPath.kt

This file was deleted.

117 changes: 29 additions & 88 deletions test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ftl.config.FtlConstants.isWindows
import ftl.http.executeWithRetry
import ftl.run.common.getDownloadPath
import ftl.test.util.FlankTestRunner
import ftl.util.ObjPath
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
Expand All @@ -29,14 +28,19 @@ import org.junit.Test
import org.junit.contrib.java.lang.system.SystemOutRule
import org.junit.runner.RunWith

private const val OBJECT_NAME = "2019-03-22_15-30-02.189000_frjt"
private const val FILE_NAME = "StandardOutputAndStandardError.txt"
private const val SHARD = "shard_0"
private const val MATRIX = "matrix_1"
private const val ANDROID_DEVICE = "NexusLowRes-27-en-portrait-shard_0-rerun_1"
private const val IOS_DEVICE = "iphone8-12.0-en-portrait"
private const val LOCAL_DIR = "results"
private const val TEST_FILE_PATH = "any/path/that/is/possible"
private const val FULL_IOS_PATH = "$OBJECT_NAME/$SHARD/$IOS_DEVICE/$TEST_FILE_PATH/$FILE_NAME"
private const val FULL_ANDROID_PATH = "$OBJECT_NAME/$MATRIX/$ANDROID_DEVICE/$TEST_FILE_PATH/$FILE_NAME"

@RunWith(FlankTestRunner::class)
class TestRunnerTest {

private val gcsIosPath =
"2019-03-22_15-30-02.189000_frjt/shard_0/iphone8-12.0-en-portrait/TestLogs/Test-Transient Testing-2019.03.22_08-29-41--0700.xcresult/1_Test/Diagnostics/EarlGreyExampleSwiftTests-C6803D8C-4BDB-4C84-8945-9AC64056FBA4/EarlGreyExampleSwiftTests-EDBFF942-A88A-46A5-87CA-A1E29555C2CA/StandardOutputAndStandardError.txt"
private val gcsAndroidPath =
"2019-03-22_15-30-02.189000_frjt/matrix_1/iphone8-12.0-en-portrait-shard_0/StandardOutputAndStandardError.txt"
private val localResultDir = "results"
private val iosArgs = mockk<IosArgs>()
private val androidArgs = mockk<AndroidArgs>()

Expand All @@ -48,125 +52,62 @@ class TestRunnerTest {

@Test
fun `Verify getDownloadPath localResultDir false and keepFilePath false - ios`() {
val parsed = ObjPath.legacyParse(gcsIosPath)

every { iosArgs.localResultDir } returns localResultDir
every { iosArgs.localResultDir } returns LOCAL_DIR
every { iosArgs.useLocalResultDir() } returns false
every { iosArgs.keepFilePath } returns false

val downloadFile = getDownloadPath(iosArgs, gcsIosPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.objName,
parsed.shardName,
parsed.deviceName,
parsed.fileName
)
)
val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH)
assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$OBJECT_NAME/$SHARD/$IOS_DEVICE/$FILE_NAME"))
}

@Test
fun `Verify getDownloadPath localResultDir false and keepFilePath true - ios`() {
val parsed = ObjPath.legacyParse(gcsIosPath)

every { iosArgs.localResultDir } returns localResultDir
every { iosArgs.localResultDir } returns LOCAL_DIR
every { iosArgs.useLocalResultDir() } returns false
every { iosArgs.keepFilePath } returns true

val downloadFile = getDownloadPath(iosArgs, gcsIosPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.objName,
parsed.shardName,
parsed.deviceName,
parsed.filePathName,
parsed.fileName
)
)
val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH)
assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$FULL_IOS_PATH"))
}

@Test
fun `Verify getDownloadPath localResultDir true and keepFilePath false - ios`() {
val parsed = ObjPath.legacyParse(gcsIosPath)

every { iosArgs.localResultDir } returns localResultDir
every { iosArgs.localResultDir } returns LOCAL_DIR
every { iosArgs.useLocalResultDir() } returns true
every { iosArgs.keepFilePath } returns false

val downloadFile = getDownloadPath(iosArgs, gcsIosPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.shardName,
parsed.deviceName,
parsed.fileName
)
)
val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH)
assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$SHARD/$IOS_DEVICE/$FILE_NAME"))
}

@Test
fun `Verify getDownloadPath localResultDir true and keepFilePath true - ios`() {
val parsed = ObjPath.legacyParse(gcsIosPath)

every { iosArgs.localResultDir } returns localResultDir
every { iosArgs.localResultDir } returns LOCAL_DIR
every { iosArgs.useLocalResultDir() } returns true
every { iosArgs.keepFilePath } returns true

val downloadFile = getDownloadPath(iosArgs, gcsIosPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.shardName,
parsed.deviceName,
parsed.filePathName,
parsed.fileName
)
)
val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH)
assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$SHARD/$IOS_DEVICE/$TEST_FILE_PATH/$FILE_NAME"))
}

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

every { androidArgs.localResultDir } returns localResultDir
every { androidArgs.localResultDir } returns LOCAL_DIR
every { androidArgs.useLocalResultDir() } returns true
every { androidArgs.keepFilePath } returns true

val downloadFile = getDownloadPath(androidArgs, gcsAndroidPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.matrixName,
parsed.shardName,
parsed.deviceName,
parsed.filePathName,
parsed.fileName
)
)
val downloadFile = getDownloadPath(androidArgs, FULL_ANDROID_PATH)
assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$MATRIX/$ANDROID_DEVICE/$TEST_FILE_PATH/$FILE_NAME"))
}

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

every { androidArgs.localResultDir } returns localResultDir
every { androidArgs.localResultDir } returns LOCAL_DIR
every { androidArgs.useLocalResultDir() } returns false
every { androidArgs.keepFilePath } returns true

val downloadFile = getDownloadPath(androidArgs, gcsAndroidPath)
assertThat(downloadFile).isEqualTo(
Paths.get(
localResultDir,
parsed.objName,
parsed.matrixName,
parsed.shardName,
parsed.deviceName,
parsed.filePathName,
parsed.fileName
)
)
val downloadFile = getDownloadPath(androidArgs, FULL_ANDROID_PATH)
assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$FULL_ANDROID_PATH"))
}

@Test
Expand Down
32 changes: 0 additions & 32 deletions test_runner/src/test/kotlin/ftl/util/ObjPathTest.kt

This file was deleted.

0 comments on commit 2ace9ac

Please sign in to comment.