Skip to content

Commit

Permalink
feat(ios): verify supported platform for Apple bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy committed Feb 19, 2024
1 parent 02ece2b commit c5ee4dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.malinskiy.marathon.apple.logparser.parser

enum class DeviceFailureReason { Unknown, FailedRunner, ConnectionAbort, InvalidSimulatorIdentifier, UnreachableHost, ServicesUnavailable }
enum class DeviceFailureReason { Unknown, FailedRunner, ConnectionAbort, InvalidSimulatorIdentifier, UnreachableHost, ServicesUnavailable, IncompatibleDevice }

class DeviceFailureException(
val reason: DeviceFailureReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class BundleInfo(delegate: NSDictionary) : PropertyList<NSDictionary>(delegate)
val categorization = Categorization(delegate)
val identification = Identification(delegate)
val naming = Naming(delegate)
val undocumented = Undocumented(delegate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package com.malinskiy.marathon.apple.xctestrun

import com.malinskiy.marathon.apple.AppleDevice
import com.malinskiy.marathon.apple.RemoteFileManager
import com.malinskiy.marathon.apple.logparser.parser.DeviceFailureException
import com.malinskiy.marathon.apple.logparser.parser.DeviceFailureReason
import com.malinskiy.marathon.apple.model.AppleTestBundle
import com.malinskiy.marathon.apple.model.Arch
import com.malinskiy.marathon.apple.model.Sdk
import com.malinskiy.marathon.apple.plist.bundle.BundleInfo
import com.malinskiy.marathon.apple.xctestrun.v2.TestConfiguration
import com.malinskiy.marathon.apple.xctestrun.v2.TestTarget
import com.malinskiy.marathon.apple.xctestrun.v2.Xctestrun
import com.malinskiy.marathon.config.exceptions.ConfigurationException
import com.malinskiy.marathon.config.vendor.apple.TestType
import com.malinskiy.marathon.config.vendor.apple.ios.XcresultConfiguration
import com.malinskiy.marathon.exceptions.DeviceLostException
import com.malinskiy.marathon.exceptions.DeviceSetupException
import com.malinskiy.marathon.exceptions.TransferException
import java.io.File
Expand All @@ -28,6 +32,8 @@ class TestRootFactory(

val testRoot = remoteFileManager.remoteTestRoot()
remoteFileManager.createRemoteDirectory(testRoot)
validateDeviceCompatibility(device, bundle)

val xctestrun = when (testType) {
TestType.XCUITEST -> generateXCUITest(testRoot, remoteFileManager, bundle, useXctestParser)
TestType.XCTEST -> generateXCTest(testRoot, remoteFileManager, bundle, useXctestParser)
Expand All @@ -46,6 +52,29 @@ class TestRootFactory(
}
}

private fun validateDeviceCompatibility(device: AppleDevice, bundle: AppleTestBundle) {
bundle.applicationBundleInfo?.let { validateDeviceBundle(it, device) }
validateDeviceBundle(bundle.testBundleInfo, device)
}

private fun validateDeviceBundle(bundle: BundleInfo, device: AppleDevice) {
val bundleSupportedPlatforms = bundle.undocumented.bundleSupportedPlatforms
val platform = device.sdk.platformName
if (!bundleSupportedPlatforms.contains(platform)) {
throw DeviceLostException(
DeviceFailureException(
reason = DeviceFailureReason.IncompatibleDevice,
message = "Device ${device.serialNumber} with platform $platform " +
"is incompatible with bundle's supported platforms [${
bundleSupportedPlatforms.joinToString(
","
)
}]"
)
)
}
}

private suspend fun generateXCUITest(
testRoot: String,
remoteFileManager: RemoteFileManager,
Expand Down

0 comments on commit c5ee4dc

Please sign in to comment.