1
1
use std:: time:: Duration ;
2
2
3
3
use crate :: {
4
- core:: { client:: Client , error:: WaitContainerError , wait:: WaitStrategy , ExecCommand } ,
4
+ core:: {
5
+ client:: Client , error:: WaitContainerError , wait:: WaitStrategy , CmdWaitFor , ExecCommand ,
6
+ } ,
5
7
ContainerAsync , Image ,
6
8
} ;
7
9
8
10
#[ derive( Debug , Clone ) ]
9
11
pub struct CommandStrategy {
10
- expected_code : i64 ,
11
12
poll_interval : Duration ,
12
13
command : ExecCommand ,
13
14
fail_fast : bool ,
@@ -18,7 +19,6 @@ impl CommandStrategy {
18
19
pub fn new ( ) -> Self {
19
20
Self {
20
21
command : ExecCommand :: default ( ) ,
21
- expected_code : 0 ,
22
22
poll_interval : Duration :: from_millis ( 100 ) ,
23
23
fail_fast : false ,
24
24
}
@@ -56,6 +56,11 @@ impl WaitStrategy for CommandStrategy {
56
56
client : & Client ,
57
57
container : & ContainerAsync < I > ,
58
58
) -> crate :: core:: error:: Result < ( ) > {
59
+ let expected_code = match self . command . clone ( ) . cmd_ready_condition {
60
+ CmdWaitFor :: Exit { code } => code,
61
+ _ => Some ( 0 ) ,
62
+ } ;
63
+
59
64
loop {
60
65
let container_state = client
61
66
. inspect ( container. id ( ) )
@@ -82,15 +87,17 @@ impl WaitStrategy for CommandStrategy {
82
87
let exit_code = inspect_result. exit_code ;
83
88
running = inspect_result. running . unwrap_or ( false ) ;
84
89
85
- if self . fail_fast && exit_code != Some ( self . expected_code ) {
86
- return Err ( WaitContainerError :: UnexpectedExitCode {
87
- expected : self . expected_code ,
88
- actual : exit_code,
90
+ if let Some ( code) = expected_code {
91
+ if self . fail_fast && exit_code != expected_code {
92
+ return Err ( WaitContainerError :: UnexpectedExitCode {
93
+ expected : code,
94
+ actual : exit_code,
95
+ }
96
+ . into ( ) ) ;
89
97
}
90
- . into ( ) ) ;
91
98
}
92
99
93
- if exit_code == Some ( self . expected_code ) {
100
+ if exit_code == expected_code {
94
101
return Ok ( ( ) ) ;
95
102
}
96
103
0 commit comments