Skip to content

Commit

Permalink
Fix upload to not directly reference the client
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloox authored and mergify-bot committed Apr 29, 2021
1 parent 57372ca commit d0c2145
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 29 deletions.
22 changes: 0 additions & 22 deletions test_runner/src/main/kotlin/ftl/client/google/FileReference.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
package ftl.client.google

import ftl.api.FileReference
import ftl.api.RemoteStorage
import ftl.api.uploadToRemoteStorage
import ftl.args.IArgs
import ftl.reports.xml.model.JUnitTestResult
import ftl.reports.xml.parseAllSuitesXml
import ftl.run.exception.FlankGeneralError
import java.nio.file.Files
import java.nio.file.Paths

fun IArgs.uploadIfNeeded(file: FileReference): FileReference =
file.uploadIfNeeded(
rootGcsBucket = resultsBucket,
runGcsPath = resultsDir
)

fun FileReference.uploadIfNeeded(
rootGcsBucket: String,
runGcsPath: String
): FileReference = if (remote.isNotBlank()) this else copy(remote = upload(local, rootGcsBucket, runGcsPath))

fun upload(file: String, rootGcsBucket: String, runGcsPath: String): String {
return uploadToRemoteStorage(
RemoteStorage.Dir(rootGcsBucket, runGcsPath),
RemoteStorage.Data(file, Files.readAllBytes(Paths.get(file)))
)
}

internal fun fileReferenceDownload(fileReference: FileReference, ifNeeded: Boolean, ignoreErrors: Boolean): String {
if (!ignoreErrors) {
if (fileReference.local.isBlank() && fileReference.remote.isBlank()) throw FlankGeneralError("Cannot create empty FileReference")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ object ReportManager {
newTestResult.mergeTestTimes(oldTestResult)
}

if (oldTestResult != null) {
printActual(oldTestResult, newTestResult, args, testShardChunks)
}
printActual(oldTestResult, newTestResult, args, testShardChunks)

GcStorage.uploadJunitXml(newTestResult, args)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import ftl.api.FileReference
import ftl.args.AndroidArgs
import ftl.args.ArgsHelper
import ftl.args.CalculateShardsResult
import ftl.client.google.downloadIfNeeded
import ftl.config.FtlConstants
import ftl.filter.TestFilter
import ftl.filter.TestFilters
Expand All @@ -25,6 +24,7 @@ import ftl.run.model.InstrumentationTestContext
import ftl.shard.Chunk
import ftl.shard.createShardsByTestForShards
import ftl.util.FlankTestMethod
import ftl.util.downloadIfNeeded
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package ftl.run.platform.android

import ftl.args.AndroidArgs
import ftl.args.IosArgs
import ftl.client.google.uploadIfNeeded
import ftl.run.model.AndroidTestContext
import ftl.run.model.GameLoopContext
import ftl.run.model.InstrumentationTestContext
import ftl.run.model.RoboTestContext
import ftl.run.model.SanityRoboTestContext
import ftl.util.asFileReference
import ftl.util.uploadIfNeeded
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package ftl.run.platform.ios

import flank.common.join
import ftl.args.IosArgs
import ftl.client.google.uploadIfNeeded
import ftl.run.model.GameloopTestContext
import ftl.run.model.IosTestContext
import ftl.util.ShardCounter
import ftl.util.asFileReference
import ftl.util.uploadIfNeeded
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import flank.common.join
import ftl.api.RemoteStorage
import ftl.api.uploadToRemoteStorage
import ftl.args.IosArgs
import ftl.client.google.uploadIfNeeded
import ftl.ios.xctest.xcTestRunFlow
import ftl.run.model.IosTestContext
import ftl.run.model.XcTestContext
import ftl.util.ShardCounter
import ftl.util.asFileReference
import ftl.util.uploadIfNeeded
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

Expand Down
22 changes: 22 additions & 0 deletions test_runner/src/main/kotlin/ftl/util/FileReference.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
package ftl.util

import ftl.api.FileReference
import ftl.api.RemoteStorage
import ftl.api.downloadFileReference
import ftl.api.uploadToRemoteStorage
import ftl.args.IArgs
import ftl.config.FtlConstants
import java.nio.file.Files
import java.nio.file.Paths

fun String.asFileReference(): FileReference =
if (startsWith(FtlConstants.GCS_PREFIX)) FileReference(remote = this) else FileReference(local = this)

fun IArgs.getSmartFlankGCSPathAsFileReference() = this.smartFlankGcsPath.asFileReference()

internal fun FileReference.downloadIfNeeded() = downloadFileReference(this, true, false)

fun IArgs.uploadIfNeeded(file: FileReference): FileReference =
file.uploadIfNeeded(
rootGcsBucket = resultsBucket,
runGcsPath = resultsDir
)

fun FileReference.uploadIfNeeded(
rootGcsBucket: String,
runGcsPath: String
): FileReference = if (remote.isNotBlank()) this else copy(remote = upload(local, rootGcsBucket, runGcsPath))

fun upload(file: String, rootGcsBucket: String, runGcsPath: String): String {
return uploadToRemoteStorage(
RemoteStorage.Dir(rootGcsBucket, runGcsPath),
RemoteStorage.Data(file, Files.readAllBytes(Paths.get(file)))
)
}
1 change: 1 addition & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ftl.test.util.TestHelper.assert
import ftl.test.util.TestHelper.getPath
import ftl.test.util.TestHelper.getThrowable
import ftl.test.util.assertThrowsWithMessage
import ftl.util.asFileReference
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.mockkStatic
Expand Down

0 comments on commit d0c2145

Please sign in to comment.