@@ -105,30 +105,24 @@ impl TimeThreshold {
105
105
/// value.
106
106
pub fn from_env_var ( env_var_name : & str ) -> Option < Self > {
107
107
let durations_str = env:: var ( env_var_name) . ok ( ) ?;
108
+ let ( warn_str, critical_str) = durations_str. split_once ( ',' ) . unwrap_or_else ( || {
109
+ panic ! (
110
+ "Duration variable {} expected to have 2 numbers separated by comma, but got {}" ,
111
+ env_var_name, durations_str
112
+ )
113
+ } ) ;
108
114
109
- // Split string into 2 substrings by comma and try to parse numbers.
110
- let mut durations = durations_str. splitn ( 2 , ',' ) . map ( |v| {
115
+ let parse_u64 = |v| {
111
116
u64:: from_str ( v) . unwrap_or_else ( |_| {
112
117
panic ! (
113
118
"Duration value in variable {} is expected to be a number, but got {}" ,
114
119
env_var_name, v
115
120
)
116
121
} )
117
- } ) ;
118
-
119
- // Callback to be called if the environment variable has unexpected structure.
120
- let panic_on_incorrect_value = || {
121
- panic ! (
122
- "Duration variable {} expected to have 2 numbers separated by comma, but got {}" ,
123
- env_var_name, durations_str
124
- ) ;
125
122
} ;
126
123
127
- let ( warn, critical) = (
128
- durations. next ( ) . unwrap_or_else ( panic_on_incorrect_value) ,
129
- durations. next ( ) . unwrap_or_else ( panic_on_incorrect_value) ,
130
- ) ;
131
-
124
+ let warn = parse_u64 ( warn_str) ;
125
+ let critical = parse_u64 ( critical_str) ;
132
126
if warn > critical {
133
127
panic ! ( "Test execution warn time should be less or equal to the critical time" ) ;
134
128
}
0 commit comments