Skip to content

Commit 7fc5e46

Browse files
committed
Minor refactor in AuthMonitor unit tests
1 parent 689733a commit 7fc5e46

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/auth_monitor.test.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub fn when_max_failed_attempts_limit_is_reached_then_update_callback_is_called(
3030
},
3131
})
3232
.expect("Error creating AuthMonitor");
33-
auth_monitor.update(|| panic!("Callback call was not expected"));
3433

34+
expect_no_update_callback_call(&mut auth_monitor);
3535
expect_update_callback_is_not_called_after_writing_auth_failed_messages(
3636
&mut auth_monitor,
3737
&mut file,
@@ -50,6 +50,12 @@ pub fn when_max_failed_attempts_limit_is_reached_then_update_callback_is_called(
5050
}
5151
}
5252

53+
fn expect_no_update_callback_call(auth_monitor: &mut AuthMonitor) {
54+
auth_monitor.update(|| {
55+
panic!("Callback call was not expected");
56+
});
57+
}
58+
5359
fn expect_update_callback_is_not_called_after_writing_auth_failed_messages(
5460
auth_monitor: &mut AuthMonitor,
5561
file: &mut TestFile,
@@ -59,7 +65,7 @@ fn expect_update_callback_is_not_called_after_writing_auth_failed_messages(
5965
let message_index = i % AUTH_FAILED_TEST_MESSAGES.len();
6066
let message = create_log_line(AUTH_FAILED_TEST_MESSAGES[message_index]);
6167
file.write(&message);
62-
auth_monitor.update(|| panic!("Callback call was not expected"));
68+
expect_no_update_callback_call(auth_monitor);
6369
}
6470
}
6571

@@ -70,7 +76,7 @@ fn expect_update_callback_is_not_called_after_writing_other_messages(
7076
for other_message in OTHER_TEST_MESSAGES {
7177
let message = create_log_line(other_message);
7278
file.write(&message);
73-
auth_monitor.update(|| panic!("Callback call was not expected"));
79+
expect_no_update_callback_call(auth_monitor);
7480
}
7581
}
7682

@@ -97,8 +103,8 @@ pub fn when_reset_after_seconds_passed_then_failed_attempts_count_is_reset() {
97103
options,
98104
})
99105
.expect("Error creating AuthMonitor");
100-
auth_monitor.update(|| panic!("Callback call was not expected"));
101106

107+
expect_no_update_callback_call(&mut auth_monitor);
102108
expect_update_callback_is_not_called_after_writing_auth_failed_messages(
103109
&mut auth_monitor,
104110
&mut file,

0 commit comments

Comments
 (0)