-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.rs
More file actions
743 lines (651 loc) · 23.1 KB
/
Copy pathmod.rs
File metadata and controls
743 lines (651 loc) · 23.1 KB
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
mod android;
mod ios;
pub mod maestro;
pub mod model;
mod validate;
use anyhow::Result;
use clap::CommandFactory;
use clap::{Args, Parser, Subcommand};
use std::path::PathBuf;
use crate::cli::model::BatchIsolation;
use crate::errors::default_error_handler;
use crate::interactor::{DownloadArtifactsInteractor, GetDeviceCatalogInteractor};
#[derive(Parser)]
#[command(
name = "marathon-cloud",
about = "Marathon Cloud command-line interface",
long_about = None,
author,
version,
about,
arg_required_else_help = true
)]
pub struct Cli {
#[command(subcommand)]
command: Option<Commands>,
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,
}
impl Cli {
pub async fn run() -> Result<()> {
let cli = Cli::parse();
simple_logger::SimpleLogger::new()
.env()
.with_level(cli.verbose.log_level_filter())
.init()
.unwrap();
let result = match cli.command {
Some(Commands::Run(args)) => {
let run_cmd = args.command;
match run_cmd {
RunCommands::Android {
application,
test_application,
os_version,
system_image,
device,
common,
api_args,
flavor,
instrumentation_arg,
retry_args,
analytics_args,
pull_files,
application_bundle,
library_bundle,
profiling_args,
mock_location,
} => {
android::run(
application,
test_application,
os_version,
system_image,
device,
common,
api_args,
flavor,
instrumentation_arg,
retry_args,
analytics_args,
profiling_args,
pull_files,
application_bundle,
library_bundle,
mock_location,
)
.await
}
RunCommands::iOS {
application,
test_application,
os_version,
device,
xcode_version,
common,
api_args,
xctestrun_env,
xctestrun_test_env,
xctestplan_filter_file,
xctestplan_target_name,
retry_args,
analytics_args,
test_timeout_default,
test_timeout_max,
granted_permission,
batch_isolation,
} => {
ios::run(
application,
test_application,
os_version,
device,
xcode_version,
common,
api_args,
xctestrun_env,
xctestrun_test_env,
xctestplan_filter_file,
xctestplan_target_name,
retry_args,
analytics_args,
test_timeout_default,
test_timeout_max,
granted_permission,
batch_isolation,
)
.await
}
RunCommands::Maestro { command } => match command {
MaestroRunCommands::iOS {
application,
test_application,
os_version,
device,
xcode_version,
common,
api_args,
retry_args,
analytics_args,
maestro_env,
flow,
} => {
ios::maestro::run(
application,
test_application,
flow,
os_version,
device,
xcode_version,
common,
api_args,
maestro_env,
retry_args,
analytics_args,
)
.await
}
MaestroRunCommands::Android {
application,
test_application,
os_version,
device,
common,
api_args,
retry_args,
analytics_args,
maestro_env,
flow,
} => {
android::maestro::run(
application,
test_application,
flow,
os_version,
device,
common,
api_args,
maestro_env,
retry_args,
analytics_args,
)
.await
}
},
}
}
Some(Commands::Download(args)) => {
let interactor = DownloadArtifactsInteractor {};
let _ = interactor
.execute(
&args.api_args.base_url,
&args.api_args.api_key,
&args.id,
args.wait,
&args.output,
args.glob,
args.progress_args.no_progress_bars,
)
.await;
Ok(true)
}
Some(Commands::Devices(args)) => {
let run_cmd = args.command;
let interactor = GetDeviceCatalogInteractor {};
match run_cmd {
DevicesCommands::Android {
api_args,
progress_args,
} => {
let _ = interactor
.execute(
&api_args.base_url,
&api_args.api_key,
&model::Platform::Android,
progress_args.no_progress_bars,
)
.await;
}
}
Ok(true)
}
Some(Commands::Completions { shell }) => {
let mut app = Self::command();
let bin_name = app.get_name().to_string();
clap_complete::generate(shell, &mut app, bin_name, &mut std::io::stdout());
Ok(true)
}
None => Ok(true),
};
match result {
Ok(true) => ::std::process::exit(0),
Ok(false) => ::std::process::exit(1),
Err(error) => {
let stderr = std::io::stderr();
default_error_handler(error.into(), &mut stderr.lock());
::std::process::exit(1);
}
}
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Subcommand)]
enum Commands {
#[clap(about = "Submit a test run")]
Run(RunArgs),
#[clap(about = "Get supported devices")]
Devices(DevicesArgs),
#[clap(about = "Download artifacts from a previous test run")]
Download(DownloadArgs),
#[clap(about = "Output shell completion code for the specified shell (bash, zsh, fish)")]
Completions { shell: clap_complete::Shell },
}
#[derive(Debug, clap::Parser)]
#[command(args_conflicts_with_subcommands = true)]
struct RunArgs {
#[command(subcommand)]
command: RunCommands,
}
/// Options valid for any subcommand.
#[derive(Debug, Clone, clap::Args)]
struct CommonRunArgs {
#[arg(short, long, help = "Output folder for test run results")]
output: Option<PathBuf>,
#[arg(long, help = "Run each test in isolation, i.e. isolated batching.")]
isolated: Option<bool>,
#[arg(
long,
help = "Test filters supplied as a YAML file following the schema at https://docs.marathonlabs.io/runner/configuration/filtering/#filtering-logic.
For iOS see also https://docs.marathonlabs.io/runner/next/ios#test-plans.
Please be aware that if you use the 'annotation' filter type on Android, you should add the 'com.malinskiy.adam:android-junit4-test-annotation-producer:<version>' test dependency to parse custom test annotations."
)]
filter_file: Option<PathBuf>,
#[arg(
long,
help = "Wait for test run to finish if true, exits after triggering a run if false"
)]
wait: Option<bool>,
#[arg(
long,
help = "Name for run, for example it could be description of commit"
)]
name: Option<String>,
#[arg(
long,
help = "Optional link, for example it could be a link to source control commit or CI run"
)]
link: Option<String>,
#[arg(
long,
help = "Branch for run, for example it could be git branch like develop or feature/about-screen"
)]
branch: Option<String>,
#[arg(
long,
help = "When tests fail and this option is true then cli will exit with code 0. By default, cli will exit with code 1 in case of test failures and 0 for passing tests"
)]
ignore_test_failures: Option<bool>,
#[arg(
long,
help = "Collect code coverage if true. Requires setup external to Marathon Cloud, e.g. build flags, jacoco jar added to classpath, etc"
)]
code_coverage: Option<bool>,
#[command(flatten)]
progress_args: ProgressArgs,
#[command(flatten)]
result_file_args: ResultFileArgs,
#[arg(
long,
help = "Limit maximum number of concurrent devices.
Warning: Using this argument may BREAK the 15-minute run promise!"
)]
concurrency_limit: Option<u32>,
#[arg(long, help = "The unique identifier (slug) for the project")]
project: Option<String>,
}
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct DownloadArgs {
#[arg(short, long, help = "Output folder for test run results")]
output: PathBuf,
#[arg(long, help = "Test run id")]
id: String,
#[arg(
long,
default_value_t = true,
help = "Wait for test run to finish if true, exits immediately if false"
)]
wait: bool,
#[arg(
long,
help = "Only files matching this glob will be downloaded, i.e. 'tests/**' will download only the JUnit xml files"
)]
glob: Option<String>,
#[command(flatten)]
api_args: ApiArgs,
#[command(flatten)]
progress_args: ProgressArgs,
#[command(flatten)]
result_file_args: ResultFileArgs,
}
#[derive(Debug, clap::Parser)]
#[command(args_conflicts_with_subcommands = true)]
struct DevicesArgs {
#[command(subcommand)]
command: DevicesCommands,
}
#[derive(Debug, Subcommand)]
enum DevicesCommands {
#[clap(about = "Print supported Android devices")]
Android {
#[command(flatten)]
api_args: ApiArgs,
#[command(flatten)]
progress_args: ProgressArgs,
},
}
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct ApiArgs {
#[arg(long, env("MARATHON_CLOUD_API_KEY"), help = "Marathon Cloud API key")]
api_key: String,
#[arg(
long,
default_value = "https://cloud.marathonlabs.io/api",
help = "Base url for Marathon Cloud API"
)]
base_url: String,
}
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
pub(crate) struct RetryArgs {
#[arg(
long,
conflicts_with = "no_retries",
help = "Number of allowed uncompleted executions per test"
)]
retry_quota_test_uncompleted: Option<u32>,
#[arg(
long,
conflicts_with = "no_retries",
help = "Number of allowed preventive retries per test"
)]
retry_quota_test_preventive: Option<u32>,
#[arg(
long,
conflicts_with = "no_retries",
help = "Number of allowed reactive retries per test"
)]
retry_quota_test_reactive: Option<u32>,
#[arg(long, default_value_t = false, help = "Disable all retries")]
no_retries: bool,
}
impl RetryArgs {
fn new(
retry_quota_test_uncompleted: Option<u32>,
retry_quota_test_preventive: Option<u32>,
retry_quota_test_reactive: Option<u32>,
) -> Self {
Self {
retry_quota_test_uncompleted,
retry_quota_test_preventive,
retry_quota_test_reactive,
no_retries: false,
}
}
}
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct AnalyticsArgs {
#[arg(
long,
help = "If true then test run will not affect any statistical measurements"
)]
analytics_read_only: Option<bool>,
}
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct ProfilingArgs {
#[arg(long, default_value_t = false, help = "Profile tests")]
profiling: bool,
}
#[derive(Debug, Args, Clone)]
#[command(args_conflicts_with_subcommands = true)]
struct ProgressArgs {
#[arg(long, default_value_t = false, help = "Disable animated progress bars")]
no_progress_bars: bool,
}
#[derive(Debug, Args, Clone)]
#[command(args_conflicts_with_subcommands = true)]
struct ResultFileArgs {
#[arg(
long,
help = "Result file path in a machine-readable format. You can specify the format via extension [yaml,json]"
)]
result_file: Option<PathBuf>,
}
#[derive(Debug, Subcommand)]
enum RunCommands {
#[clap(about = "Run tests for Android")]
Android {
#[arg(
short,
long,
help = "application filepath, example: /home/user/workspace/sample.apk"
)]
application: Option<PathBuf>,
#[arg(
short,
long,
help = "test application filepath, example: /home/user/workspace/testSample.apk"
)]
test_application: Option<PathBuf>,
#[arg(value_enum, long, help = "OS version")]
os_version: Option<android::OsVersion>,
#[arg(value_enum, long, help = "Runtime system image")]
system_image: Option<android::SystemImage>,
#[arg(
value_enum,
long,
help = "Device type id. Use `marathon-cloud devices android` to get a list of supported devices"
)]
device: Option<String>,
#[arg(value_enum, long, help = "Test flavor")]
flavor: Option<android::Flavor>,
#[command(flatten)]
common: CommonRunArgs,
#[command(flatten)]
api_args: ApiArgs,
#[command(flatten)]
retry_args: RetryArgs,
#[command(flatten)]
analytics_args: AnalyticsArgs,
#[command(flatten)]
profiling_args: ProfilingArgs,
#[arg(long, help = "Instrumentation arguments, example: FOO=BAR")]
instrumentation_arg: Option<Vec<String>>,
#[arg(
long,
help = "Pull files from devices after the test run.
The format is 'ROOT:PATH' where ROOT is one of [EXTERNAL_STORAGE, APP_DATA] and PATH is a relative path to the target file or directory.
Example: 'EXTERNAL_STORAGE:Documents/some-results', 'APP_DATA:files/my_folder/some_file.txt'.
Note: Files with the same name and path from different devices may overwrite each other."
)]
pull_files: Option<Vec<String>>,
#[arg(
long,
conflicts_with_all = &["application", "test_application"],
help = "Application bundle containing the application apk and test application apk.
The format is '<app_apk_path>,<test_apk_path>'. The delimeter is a comma.
Example: '--application-bundle apks/feature1-app-debug.apk,apks/feature1-app-debug-androidTest.apk --application-bundle apks/feature2-app-debug.apk,apks/feature2-app-debug-androidTest.apk'"
)]
application_bundle: Option<Vec<String>>,
#[arg(
long,
conflicts_with_all = &["application", "test_application"],
help = "Library bundle containing the library test apk. Library testing requires only Test APK.
The format is '<test_apk_path>'.
Example: '--library-bundle apks/library1-debug-androidTest.apk --library-bundle apks/library2-debug-androidTest.apk'"
)]
library_bundle: Option<Vec<PathBuf>>,
#[arg(
long,
default_value_t = false,
help = "Allow mock location access for application"
)]
mock_location: bool,
},
#[allow(non_camel_case_types)]
#[command(name = "ios")]
#[clap(about = "Run tests for iOS")]
iOS {
#[arg(
short,
long,
help = "application filepath, example: /home/user/workspace/sample.zip"
)]
application: PathBuf,
#[arg(
short,
long,
help = "test application filepath, example: /home/user/workspace/sampleUITests-Runner.zip"
)]
test_application: PathBuf,
#[arg(value_enum, long, help = "iOS runtime version")]
os_version: Option<ios::OsVersion>,
#[arg(value_enum, long, help = "Device type")]
device: Option<ios::IosDevice>,
#[arg(value_enum, long, hide = true, help = "Xcode version")]
xcode_version: Option<ios::XcodeVersion>,
#[command(flatten)]
common: CommonRunArgs,
#[command(flatten)]
api_args: ApiArgs,
#[command(flatten)]
retry_args: RetryArgs,
#[command(flatten)]
analytics_args: AnalyticsArgs,
#[arg(
value_enum,
long,
help = "Batch isolation mode. Use app uninstall if you want to uninstall app between test batches"
)]
batch_isolation: Option<BatchIsolation>,
#[arg(
long,
help = "xctestrun environment variable (EnvironmentVariables item), example FOO=BAR"
)]
xctestrun_env: Option<Vec<String>>,
#[arg(
long,
help = "xctestrun testing environment variable (TestingEnvironmentVariables item), example FOO=BAR"
)]
xctestrun_test_env: Option<Vec<String>>,
#[arg(long, help = "Test filters supplied as .xctestplan file")]
xctestplan_filter_file: Option<PathBuf>,
#[arg(long, help = "Target name to use for test filtering in .xctestplan")]
xctestplan_target_name: Option<String>,
#[arg(
long,
default_value = "300",
help = "Default timeout for each test in seconds"
)]
test_timeout_default: Option<u32>,
#[arg(
long,
help = "Maximum test timeout in seconds, overriding all other test timeout settings"
)]
test_timeout_max: Option<u32>,
#[arg(
long,
help = "Grant permission to application.
Important: Granting is conducted before each test batch (not each test). If you need to grant before each test, please use --isolated mode.
Available permissions: calendar, contacts-limited, contacts, location, location-always, photos-add, photos, media-library, microphone, motion, reminders, siri."
)]
granted_permission: Option<Vec<String>>,
},
#[clap(about = "Run maestro tests")]
Maestro {
#[command(subcommand)]
command: MaestroRunCommands,
},
}
#[derive(Debug, Subcommand)]
enum MaestroRunCommands {
#[allow(non_camel_case_types)]
#[command(name = "ios")]
#[clap(about = "Run maestro tests using iOS")]
iOS {
#[arg(
short,
long,
help = "application filepath, example: /home/user/workspace/sample.zip"
)]
application: PathBuf,
#[arg(
short,
long,
help = "test application filepath (a folder with maestro flows), for example: /home/user/workspace/flows"
)]
test_application: PathBuf,
#[arg(value_enum, long, help = "iOS runtime version")]
os_version: Option<ios::OsVersion>,
#[arg(value_enum, long, help = "Device type")]
device: Option<ios::IosDevice>,
#[arg(value_enum, long, hide = true, help = "Xcode version")]
xcode_version: Option<ios::XcodeVersion>,
#[command(flatten)]
common: CommonRunArgs,
#[command(flatten)]
api_args: ApiArgs,
#[command(flatten)]
retry_args: RetryArgs,
#[command(flatten)]
analytics_args: AnalyticsArgs,
#[arg(
long,
help = "maestro environment variable, example MAESTRO_APP_ID=com.example"
)]
maestro_env: Option<Vec<String>>,
flow: Vec<String>,
},
#[allow(non_camel_case_types)]
#[command(name = "android")]
#[clap(about = "Run maestro tests using Android")]
Android {
#[arg(
short,
long,
help = "application filepath, example: /home/user/workspace/sample.apk"
)]
application: PathBuf,
#[arg(
short,
long,
help = "test application filepath (a folder with maestro flows), for example: /home/user/workspace/flows"
)]
test_application: PathBuf,
#[arg(value_enum, long, help = "OS version")]
os_version: Option<android::OsVersion>,
#[arg(
value_enum,
long,
help = "Device type id. Use `marathon-cloud devices android` to get a list of supported devices"
)]
device: Option<String>,
#[command(flatten)]
common: CommonRunArgs,
#[command(flatten)]
api_args: ApiArgs,
#[command(flatten)]
retry_args: RetryArgs,
#[command(flatten)]
analytics_args: AnalyticsArgs,
#[arg(
long,
help = "maestro environment variable, example MAESTRO_APP_ID=com.example"
)]
maestro_env: Option<Vec<String>>,
flow: Vec<String>,
},
}