Skip to content

Commit 73f37d0

Browse files
acatangiuJonathanWoollett-Light
authored andcommitted
Impl PartialEq on ServerError for tests
Co-authored-by: acatangiu <[email protected]> Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 3c5d940 commit 73f37d0

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/common/mod.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ pub enum ServerError {
170170
Overflow,
171171
/// Server maximum capacity has been reached.
172172
ServerFull,
173-
/// Underflow occurred while processing messages.
174-
Underflow,
175173
/// Shutdown requested.
176174
ShutdownEvent,
175+
/// Underflow occurred while processing messages.
176+
Underflow,
177177
}
178178

179179
impl Display for ServerError {
@@ -348,6 +348,23 @@ mod tests {
348348
}
349349
}
350350

351+
impl PartialEq for ServerError {
352+
fn eq(&self, other: &Self) -> bool {
353+
use self::ServerError::*;
354+
match (self, other) {
355+
(ConnectionError(ref e), ConnectionError(ref other_e)) => e.eq(other_e),
356+
(IOError(ref e), IOError(ref other_e)) => {
357+
e.raw_os_error() == other_e.raw_os_error()
358+
}
359+
(Overflow, Overflow) => true,
360+
(ServerFull, ServerFull) => true,
361+
(ShutdownEvent, ShutdownEvent) => true,
362+
(Underflow, Underflow) => true,
363+
_ => false,
364+
}
365+
}
366+
}
367+
351368
#[test]
352369
fn test_version() {
353370
// Tests for raw()

src/server.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,11 @@ mod tests {
11511151
handler.join().unwrap();
11521152

11531153
// Expect shutdown event instead of http request event.
1154-
match &*request_result.lock().unwrap() {
1155-
Err(ServerError::ShutdownEvent) => (),
1156-
v => {
1157-
panic!("Expected shutdown event, instead got {:?}.", v)
1158-
}
1159-
};
1154+
let res = request_result.lock().unwrap();
1155+
assert_eq!(
1156+
res.as_ref().unwrap_err(),
1157+
&ServerError::ShutdownEvent,
1158+
"Expected shutdown event, instead got {res:?}"
1159+
);
11601160
}
11611161
}

0 commit comments

Comments
 (0)