@@ -105,30 +105,24 @@ impl TimeThreshold {
105105 /// value.
106106 pub fn from_env_var ( env_var_name : & str ) -> Option < Self > {
107107 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+ } ) ;
108114
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| {
111116 u64:: from_str ( v) . unwrap_or_else ( |_| {
112117 panic ! (
113118 "Duration value in variable {} is expected to be a number, but got {}" ,
114119 env_var_name, v
115120 )
116121 } )
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- ) ;
125122 } ;
126123
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) ;
132126 if warn > critical {
133127 panic ! ( "Test execution warn time should be less or equal to the critical time" ) ;
134128 }
0 commit comments