-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor config entities and arguments #831
Conversation
Codecov Report
@@ Coverage Diff @@
## master #831 +/- ##
============================================
+ Coverage 80.14% 81.15% +1.01%
+ Complexity 674 637 -37
============================================
Files 151 166 +15
Lines 3087 3226 +139
Branches 443 463 +20
============================================
+ Hits 2474 2618 +144
- Misses 336 343 +7
+ Partials 277 265 -12 |
if (smartFlankGcsPath.count { it == '/' } <= 2 || !smartFlankGcsPath.endsWith(".xml")) { | ||
throw FlankFatalError("smart-flank-gcs-path must be in the format gs://bucket/foo.xml") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer when instead of nested ifs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH me to. I will change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private fun CommonArgs.assertSmartFlankGcsPath(): Unit = with(smartFlankGcsPath) {
when {
isEmpty() -> Unit
startsWith(FtlConstants.GCS_PREFIX).not() -> throw FlankFatalError(
"smart-flank-gcs-path must start with gs://"
)
count { it == '/' } <= 2 || endsWith(".xml").not() -> throw FlankFatalError(
"smart-flank-gcs-path must be in the format gs://bucket/foo.xml"
)
}
}
"which don't support ansi codes, to avoid corrupted output use `single` or `verbose`."] | ||
) | ||
var outputStyle: String? = null | ||
// Flank specific | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line not needed :)
|
||
override val map = mapOf( | ||
"gcloud" to keys | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be single line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rights, I was trying to keep one convention for maps and keys in all configs. Anyway this probably shouldn't be map, rather simple pair, same about another configs.
fun deviceMap(map: Map<String, String>?) { | ||
if (map.isNullOrEmpty()) return | ||
val androidDevice = Device( | ||
model = map.getOrDefault("model", FtlConstants.defaultAndroidModel), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use "model","version" etc in IosArgs and Android args. Maybe we should move keys to const/enums?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, why not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, if both android and ios gcloud config has common device
option probably it should be in CommonGcloudConfig.
config: IosConfig? = null, | ||
gcloud: IosGcloudConfig = config!!.platform.gcloud, | ||
flank: IosFlankConfig = config!!.platform.flank, | ||
commonArgs: CommonArgs = config!!.common.createCommonArgs(config.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little bit unclear for me, config
is nullable, but later on we declare that it is not null. So probably IosConfig is not nullable type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it doesn't looks well and should be explained, config
is nullable cause when gcloud
, flank
, commonArgs
are set explicit the config
is redundant from logical perspective. Possible solution to get rid of null is:
fun createIosArgs(
config: IosConfig
) = createIosArgs(
gcloud = config.platform.gcloud,
flank = config.platform.flank,
commonArgs = config.common.createCommonArgs(config.data)
)
private fun createIosArgs(
gcloud: IosGcloudConfig,
flank: IosFlankConfig,
commonArgs: CommonArgs
) = IosArgs(
commonArgs = commonArgs,
xctestrunZip = gcloud.test!!.processFilePath("from test"),
xctestrunFile = gcloud.xctestrunFile!!.processFilePath("from xctestrun-file"),
xcodeVersion = gcloud.xcodeVersion,
devices = gcloud.device!!,
testTargets = flank.testTargets!!.filterNotNull()
)
But it gives 2 functions instead of 1 and more lines. I'm am not sure which is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me 2 functions looks much better
FlankTestMethod(it, ignored = false) | ||
}, | ||
this | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would format it
private fun IosArgs.calculateShardChunks() =
if (disableSharding) listOf(emptyList())
else ArgsHelper.calculateShards(
filteredTests = filterTests(Xctestrun.findTestNames(xctestrunFile), testTargets)
.distinct()
.map { FlankTestMethod(it, ignored = false) },
args = this
)
maxTestShards !in IArgs.AVAILABLE_SHARD_COUNT_RANGE && | ||
maxTestShards != -1 | ||
) throw FlankFatalError( | ||
"max-test-shards must be >= 1 and <= 50, or -1. But current is $maxTestShards" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use IArgs.AVAILABLE_SHARD_COUNT_RANGE.first / IArgs.AVAILABLE_SHARD_COUNT_RANGE.last in exception message.
@@ -19,3 +23,19 @@ data class Device( | |||
orientation: $orientation""".trimStartLine() | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you don't change this line but:
override fun toString(): String {
return """
- model: $model
version: $version
locale: $locale
orientation: $orientation""".trimStartLine()
}
vs
override fun toString() = """
- model: $model
version: $version
locale: $locale
orientation: $orientation""".trimStartLine()
This only for discussion to keep one style. Personally I prefer second.
This is a part of #718
Goals:
Test Plan
This refactor of cli options, yaml config, AndroidArgs and IosArgs. It doesn't bring any features or changes so the existing unit tests should cover possible regression.
Checklist