/
IosArgsTest.kt
391 lines (342 loc) · 10.4 KB
/
IosArgsTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package ftl.args
import com.google.common.truth.Truth.assertThat
import ftl.args.yml.FlankYml
import ftl.args.yml.GcloudYml
import ftl.args.yml.IosFlankYml
import ftl.args.yml.IosGcloudYml
import ftl.args.yml.IosGcloudYmlParams
import ftl.cli.firebase.test.ios.IosRunCommand
import ftl.config.Device
import ftl.test.util.FlankTestRunner
import ftl.test.util.TestHelper.absolutePath
import ftl.test.util.TestHelper.assert
import org.junit.Rule
import org.junit.Test
import org.junit.contrib.java.lang.system.SystemErrRule
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import picocli.CommandLine
@RunWith(FlankTestRunner::class)
class IosArgsTest {
private val empty = emptyList<String>()
private val testPath = "./src/test/kotlin/ftl/fixtures/tmp/EarlGreyExample.zip"
private val xctestrunFile =
"./src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos12.1-arm64e.xctestrun"
private val xctestrunFileAbsolutePath = xctestrunFile.absolutePath()
private val testAbsolutePath = testPath.absolutePath()
private val iosNonDefault = """
gcloud:
results-bucket: mockBucket
record-video: false
timeout: 70m
async: true
project: projectFoo
results-history-name: ios-history
test: $testPath
xctestrun-file: $xctestrunFile
xcode-version: 9.2
device:
- model: iphone8
version: 11.2
locale: c
orientation: d
- model: iphone8
version: 11.2
locale: c
orientation: d
flank:
testShards: 7
repeatTests: 8
test-targets-always-run:
- a/testGrantPermissions
- a/testGrantPermissions2
test-targets:
- b/testBasicSelection
- b/testBasicSelection2
"""
@Rule
@JvmField
val exceptionRule = ExpectedException.none()!!
@Rule
@JvmField
val systemErrRule = SystemErrRule().muteForSuccessfulTests()!!
@Test
fun iosArgs_invalidDeviceExits() {
exceptionRule.expectMessage("iOS 99.9 on iphoneZ is not a supported device")
val invalidDevice = listOf(Device("iphoneZ", "99.9"))
IosArgs(
GcloudYml(),
IosGcloudYml(IosGcloudYmlParams(test = testPath, xctestrunFile = xctestrunFile, device = invalidDevice)),
FlankYml(),
IosFlankYml(),
""
)
}
@Test
fun iosArgs_invalidXcodeExits() {
exceptionRule.expectMessage("Xcode 99.9 is not a supported Xcode version")
IosArgs(
GcloudYml(),
IosGcloudYml(IosGcloudYmlParams(test = testPath, xctestrunFile = xctestrunFile, xcodeVersion = "99.9")),
FlankYml(),
IosFlankYml(),
""
)
}
@Test
fun iosArgs() {
val iosArgs = IosArgs.load(iosNonDefault)
with(iosArgs) {
// GcloudYml
assert(resultsBucket, "mockBucket")
assert(recordVideo, false)
assert(testTimeout, "70m")
assert(async, true)
assert(project, "projectFoo")
assert(resultsHistoryName ?: "", "ios-history")
// IosGcloudYml
assert(xctestrunZip, testAbsolutePath)
assert(xctestrunFile, xctestrunFileAbsolutePath)
val device = Device("iphone8", "11.2", "c", "d")
assert(xcodeVersion ?: "", "9.2")
assert(devices, listOf(device, device))
// FlankYml
assert(testShards, 7)
assert(repeatTests, 8)
assert(testTargetsAlwaysRun, listOf("a/testGrantPermissions", "a/testGrantPermissions2"))
// IosFlankYml
assert(testTargets, listOf("b/testBasicSelection", "b/testBasicSelection2"))
}
}
@Test
fun iosArgs_toString() {
val iosArgs = IosArgs.load(iosNonDefault)
assert(
iosArgs.toString(), """
IosArgs
gcloud:
results-bucket: mockBucket
record-video: false
timeout: 70m
async: true
project: projectFoo
results-history-name: ios-history
# iOS gcloud
test: $testAbsolutePath
xctestrun-file: $xctestrunFileAbsolutePath
xcode-version: 9.2
device:
- model: iphone8
version: 11.2
locale: c
orientation: d
- model: iphone8
version: 11.2
locale: c
orientation: d
flank:
testShards: 7
repeatTests: 8
smartFlankGcsPath:${' '}
test-targets-always-run:
- a/testGrantPermissions
- a/testGrantPermissions2
# iOS flank
test-targets:
- b/testBasicSelection
- b/testBasicSelection2
""".trimIndent()
)
}
@Test
fun iosArgsDefault() {
val iosArgs = IosArgs.load(
"""
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
"""
)
with(iosArgs) {
// GcloudYml
assert(resultsBucket, "mockBucket")
assert(recordVideo, true)
assert(testTimeout, "15m")
assert(async, false)
assert(project, "mockProjectId")
// IosGcloudYml
assert(xctestrunZip, testAbsolutePath)
assert(xctestrunFile, xctestrunFileAbsolutePath)
assert(devices, listOf(Device("iphone8", "11.2")))
// FlankYml
assert(testShards, 1)
assert(repeatTests, 1)
assert(testTargetsAlwaysRun, emptyList<String>())
// IosFlankYml
assert(testTargets, empty)
}
}
@Test
fun negativeOneTestShards() {
val iosArgs = IosArgs.load(
"""
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
flank:
testShards: -1
"""
)
with(iosArgs) {
assert(testShards, -1)
assert(testShardChunks.size, 17)
testShardChunks.forEach { chunk -> assert(chunk.size, 1) }
}
}
@Test
fun iosArgs_emptyFlank() {
val iosArgs = IosArgs.load(
"""
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
flank:
"""
)
with(iosArgs) {
assertThat(xctestrunZip).isEqualTo(testAbsolutePath)
assertThat(xctestrunFile).isEqualTo(xctestrunFileAbsolutePath)
}
}
// gcloudYml
@Test
fun cli_resultsBucket() {
val cli = IosRunCommand()
CommandLine(cli).parse("--results-bucket=a")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
results-bucket: b
"""
assertThat(IosArgs.load(yaml).resultsBucket).isEqualTo("b")
assertThat(IosArgs.load(yaml, cli).resultsBucket).isEqualTo("a")
}
@Test
fun cli_recordVideo() {
val cli = IosRunCommand()
CommandLine(cli).parse("--record-video")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
record-video: false
"""
assertThat(IosArgs.load(yaml).recordVideo).isFalse()
assertThat(IosArgs.load(yaml, cli).recordVideo).isTrue()
}
@Test
fun cli_noRecordVideo() {
val cli = IosRunCommand()
CommandLine(cli).parse("--no-record-video")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
record-video: true
"""
assertThat(IosArgs.load(yaml).recordVideo).isTrue()
assertThat(IosArgs.load(yaml, cli).recordVideo).isFalse()
}
@Test
fun cli_timeout() {
val cli = IosRunCommand()
CommandLine(cli).parse("--timeout=1m")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
timeout: 2m
"""
assertThat(IosArgs.load(yaml).testTimeout).isEqualTo("2m")
assertThat(IosArgs.load(yaml, cli).testTimeout).isEqualTo("1m")
}
@Test
fun cli_async() {
val cli = IosRunCommand()
CommandLine(cli).parse("--async")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
async: false
"""
assertThat(IosArgs.load(yaml).async).isEqualTo(false)
assertThat(IosArgs.load(yaml, cli).async).isEqualTo(true)
}
@Test
fun cli_project() {
val cli = IosRunCommand()
CommandLine(cli).parse("--project=b")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
project: a
"""
assertThat(IosArgs.load(yaml).project).isEqualTo("a")
assertThat(IosArgs.load(yaml, cli).project).isEqualTo("b")
}
@Test
fun cli_resultsHistoryName() {
val cli = IosRunCommand()
CommandLine(cli).parse("--results-history-name=b")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
results-history-name: a
"""
assertThat(IosArgs.load(yaml).resultsHistoryName).isEqualTo("a")
assertThat(IosArgs.load(yaml, cli).resultsHistoryName).isEqualTo("b")
}
@Test
fun cli_testShards() {
val cli = IosRunCommand()
CommandLine(cli).parse("--test-shards=3")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
flank:
testShards: 2
"""
assertThat(IosArgs.load(yaml).testShards).isEqualTo(2)
assertThat(IosArgs.load(yaml, cli).testShards).isEqualTo(3)
}
@Test
fun cli_repeatTests() {
val cli = IosRunCommand()
CommandLine(cli).parse("--repeat-tests=3")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
flank:
repeatTests: 2
"""
assertThat(IosArgs.load(yaml).repeatTests).isEqualTo(2)
assertThat(IosArgs.load(yaml, cli).repeatTests).isEqualTo(3)
}
@Test
fun cli_testTargetsAlwaysRun() {
val cli = IosRunCommand()
CommandLine(cli).parse("--test-targets-always-run=com.A,com.B")
val yaml = """
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
"""
assertThat(IosArgs.load(yaml, cli).testTargetsAlwaysRun).isEqualTo(arrayListOf("com.A", "com.B"))
}
}