@@ -50,7 +50,7 @@ impl CacheResults {
50
50
}
51
51
}
52
52
53
- #[ derive( Debug , PartialEq ) ]
53
+ #[ derive( Debug , PartialEq , Clone ) ]
54
54
#[ allow( clippy:: enum_variant_names) ]
55
55
pub enum ActionRunResult {
56
56
CheckSucceeded ,
@@ -76,10 +76,20 @@ impl ActionRunResult {
76
76
}
77
77
}
78
78
79
+ #[ automock]
80
+ #[ async_trait:: async_trait]
81
+ pub trait DoctorActionRun : Send + Sync {
82
+ async fn run_action ( & self ) -> Result < ActionRunResult > ;
83
+ fn required ( & self ) -> bool ;
84
+ fn name ( & self ) -> String ;
85
+ fn help_text ( & self ) -> Option < String > ;
86
+ fn help_url ( & self ) -> Option < String > ;
87
+ }
88
+
79
89
#[ derive( Educe , Builder ) ]
80
90
#[ educe( Debug ) ]
81
91
#[ builder( setter( into) ) ]
82
- pub struct DoctorActionRun {
92
+ pub struct DefaultDoctorActionRun {
83
93
pub model : ModelRoot < DoctorGroup > ,
84
94
pub action : DoctorGroupAction ,
85
95
pub working_dir : PathBuf ,
@@ -91,9 +101,10 @@ pub struct DoctorActionRun {
91
101
pub glob_walker : Arc < dyn GlobWalker > ,
92
102
}
93
103
94
- impl DoctorActionRun {
104
+ #[ async_trait:: async_trait]
105
+ impl DoctorActionRun for DefaultDoctorActionRun {
95
106
#[ instrument( skip_all, fields( model. name = self . model. name( ) , action. name = self . action. name, action. description = self . action. description ) ) ]
96
- pub async fn run_action ( & self ) -> Result < ActionRunResult > {
107
+ async fn run_action ( & self ) -> Result < ActionRunResult > {
97
108
let check_status = self . evaluate_checks ( ) . await ?;
98
109
if check_status == CacheResults :: FixNotRequired {
99
110
return Ok ( ActionRunResult :: CheckSucceeded ) ;
@@ -124,6 +135,24 @@ impl DoctorActionRun {
124
135
Ok ( ActionRunResult :: CheckFailedFixSucceedVerifySucceed )
125
136
}
126
137
138
+ fn required ( & self ) -> bool {
139
+ self . action . required
140
+ }
141
+
142
+ fn name ( & self ) -> String {
143
+ self . action . name . to_string ( )
144
+ }
145
+
146
+ fn help_text ( & self ) -> Option < String > {
147
+ self . action . fix . help_text . clone ( )
148
+ }
149
+
150
+ fn help_url ( & self ) -> Option < String > {
151
+ self . action . fix . help_url . clone ( )
152
+ }
153
+ }
154
+
155
+ impl DefaultDoctorActionRun {
127
156
async fn update_caches ( & self ) {
128
157
if let Some ( cache_path) = & self . action . check . files {
129
158
let result = self
@@ -268,7 +297,7 @@ impl DoctorActionRun {
268
297
269
298
#[ automock]
270
299
#[ async_trait]
271
- pub trait GlobWalker {
300
+ pub trait GlobWalker : Send + Sync {
272
301
async fn have_globs_changed (
273
302
& self ,
274
303
base_dir : & Path ,
@@ -337,21 +366,18 @@ impl GlobWalker for DefaultGlobWalker {
337
366
}
338
367
339
368
#[ cfg( test) ]
340
- mod tests {
341
- use crate :: check:: { ActionRunResult , DoctorActionRun , MockGlobWalker , RuntimeError } ;
369
+ pub ( crate ) mod tests {
370
+ use crate :: check:: {
371
+ ActionRunResult , DefaultDoctorActionRun , DoctorActionRun , MockGlobWalker , RuntimeError ,
372
+ } ;
342
373
use crate :: file_cache:: { FileCache , NoOpCache } ;
374
+ use crate :: tests:: build_root_model;
343
375
use anyhow:: { anyhow, Result } ;
344
- use scope_lib:: prelude:: {
345
- DoctorGroup , DoctorGroupAction , DoctorGroupActionBuilder , DoctorGroupActionCheckBuilder ,
346
- DoctorGroupActionCommand , DoctorGroupActionFixBuilder , DoctorGroupBuilder ,
347
- DoctorGroupCachePath , MockExecutionProvider , ModelMetadataBuilder , ModelRoot ,
348
- ModelRootBuilder , OutputCaptureBuilder ,
349
- } ;
350
- use std:: collections:: BTreeMap ;
376
+ use scope_lib:: prelude:: * ;
351
377
use std:: path:: PathBuf ;
352
378
use std:: sync:: Arc ;
353
379
354
- fn build_run_fail_fix_succeed_action ( ) -> DoctorGroupAction {
380
+ pub fn build_run_fail_fix_succeed_action ( ) -> DoctorGroupAction {
355
381
DoctorGroupActionBuilder :: default ( )
356
382
. description ( "a test action" )
357
383
. name ( "action" )
@@ -373,7 +399,7 @@ mod tests {
373
399
. unwrap ( )
374
400
}
375
401
376
- fn build_file_fix_action ( ) -> DoctorGroupAction {
402
+ pub fn build_file_fix_action ( ) -> DoctorGroupAction {
377
403
DoctorGroupActionBuilder :: default ( )
378
404
. description ( "a test action" )
379
405
. name ( "action" )
@@ -395,30 +421,7 @@ mod tests {
395
421
. unwrap ( )
396
422
}
397
423
398
- fn make_model ( actions : Vec < DoctorGroupAction > ) -> ModelRoot < DoctorGroup > {
399
- let group = DoctorGroupBuilder :: default ( )
400
- . description ( "a description" )
401
- . actions ( actions)
402
- . build ( )
403
- . unwrap ( ) ;
404
-
405
- ModelRootBuilder :: default ( )
406
- . api_version ( "fake" )
407
- . kind ( "fake-kind" )
408
- . metadata (
409
- ModelMetadataBuilder :: default ( )
410
- . name ( "fake-model" )
411
- . annotations ( BTreeMap :: default ( ) )
412
- . labels ( BTreeMap :: default ( ) )
413
- . build ( )
414
- . unwrap ( ) ,
415
- )
416
- . spec ( group)
417
- . build ( )
418
- . unwrap ( )
419
- }
420
-
421
- fn command_result (
424
+ pub fn command_result (
422
425
mock : & mut MockExecutionProvider ,
423
426
command : & ' static str ,
424
427
expected_results : Vec < i32 > ,
@@ -437,16 +440,16 @@ mod tests {
437
440
} ) ;
438
441
}
439
442
440
- fn setup_test (
443
+ pub fn setup_test (
441
444
actions : Vec < DoctorGroupAction > ,
442
445
exec_runner : MockExecutionProvider ,
443
446
glob_walker : MockGlobWalker ,
444
- ) -> DoctorActionRun {
445
- let model = make_model ( actions. clone ( ) ) ;
447
+ ) -> DefaultDoctorActionRun {
448
+ let model = build_root_model ( actions. clone ( ) ) ;
446
449
let path = PathBuf :: from ( "/tmp/foo" ) ;
447
450
let file_cache: Arc < dyn FileCache > = Arc :: < NoOpCache > :: default ( ) ;
448
451
449
- DoctorActionRun {
452
+ DefaultDoctorActionRun {
450
453
model,
451
454
action : actions[ 0 ] . clone ( ) ,
452
455
working_dir : path,
0 commit comments