@@ -103,3 +103,78 @@ async fn main() -> Result<()> {
103
103
let args: Cli = Cli :: parse ( ) ;
104
104
run_tasks ( args. command , args. up_to , args. task_timeout ) . await
105
105
}
106
+ #[ cfg( test) ]
107
+ mod tests {
108
+ use super :: * ;
109
+
110
+ #[ tokio:: test]
111
+ async fn test_eval_success ( ) {
112
+ let command = vec ! [ "true" . to_owned( ) ] ;
113
+ let exit_status = eval ( & command) . await . unwrap ( ) ;
114
+ assert_eq ! ( exit_status. success( ) , true ) ;
115
+ }
116
+
117
+ #[ tokio:: test]
118
+ async fn test_eval_failure ( ) {
119
+ let command = vec ! [ "false" . to_owned( ) ] ;
120
+ let exit_status = eval ( & command) . await . unwrap ( ) ;
121
+ assert_eq ! ( exit_status. success( ) , false ) ;
122
+ }
123
+
124
+ #[ tokio:: test]
125
+ async fn test_run_task_success ( ) {
126
+ let command = vec ! [ "true" . to_owned( ) ] ;
127
+ let task_outcome = run_task ( & command, None ) . await . unwrap ( ) ;
128
+ assert_eq ! ( task_outcome, TaskOutcome :: Success ) ;
129
+ }
130
+
131
+ #[ tokio:: test]
132
+ async fn test_run_task_failure ( ) {
133
+ let command = vec ! [ "false" . to_owned( ) ] ;
134
+ let task_outcome = run_task ( & command, None ) . await . unwrap ( ) ;
135
+ assert_eq ! ( task_outcome, TaskOutcome :: Timeout ) ;
136
+ }
137
+
138
+ #[ tokio:: test]
139
+ async fn test_run_task_timeout ( ) {
140
+ let command = vec ! [ "sleep" . to_owned( ) , "10" . to_owned( ) ] ;
141
+ let task_timeout = Some ( Duration :: from_secs ( 1 ) ) ;
142
+ let task_outcome = run_task ( & command, task_timeout) . await . unwrap ( ) ;
143
+ assert_eq ! ( task_outcome, TaskOutcome :: Timeout ) ;
144
+ }
145
+
146
+ #[ tokio:: test]
147
+ async fn test_loop_task_success ( ) {
148
+ let command = vec ! [ "true" . to_owned( ) ] ;
149
+ let task_timeout = Some ( Duration :: from_secs ( 5 ) ) ;
150
+ let task_outcome = loop_task ( & command, task_timeout) . await . unwrap ( ) ;
151
+ assert_eq ! ( task_outcome, TaskOutcome :: Success ) ;
152
+ }
153
+
154
+ #[ tokio:: test]
155
+ async fn test_run_tasks_success ( ) {
156
+ let command = vec ! [ "true" . to_owned( ) ] ;
157
+ let up_to = Retry :: NumberOfTimes ( 3 ) ;
158
+ let task_timeout = Some ( Duration :: from_secs ( 5 ) ) ;
159
+ let result = run_tasks ( command, up_to, task_timeout) . await ;
160
+ assert_eq ! ( result. is_ok( ) , true ) ;
161
+ }
162
+
163
+ #[ tokio:: test]
164
+ async fn test_run_tasks_failure ( ) {
165
+ let command = vec ! [ "false" . to_owned( ) ] ;
166
+ let up_to = Retry :: NumberOfTimes ( 3 ) ;
167
+ let task_timeout = Some ( Duration :: from_secs ( 5 ) ) ;
168
+ let result = run_tasks ( command, up_to, task_timeout) . await ;
169
+ assert_eq ! ( result. is_err( ) , true ) ;
170
+ }
171
+
172
+ #[ tokio:: test]
173
+ async fn test_run_tasks_timeout ( ) {
174
+ let command = vec ! [ "sleep" . to_owned( ) , "10" . to_owned( ) ] ;
175
+ let up_to = Retry :: ForDuration ( Duration :: from_secs ( 5 ) ) ;
176
+ let task_timeout = Some ( Duration :: from_secs ( 1 ) ) ;
177
+ let result = run_tasks ( command, up_to, task_timeout) . await ;
178
+ assert_eq ! ( result. is_err( ) , true ) ;
179
+ }
180
+ }
0 commit comments