Skip to content

Commit 0b890ea

Browse files
authored
Improve test_auth error message when contains() fails (apache#6657)
1 parent 5a06eec commit 0b890ea

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

arrow-flight/examples/flight_sql_server.rs

+35-18
Original file line numberDiff line numberDiff line change
@@ -1006,30 +1006,36 @@ mod tests {
10061006
async fn test_auth() {
10071007
test_all_clients(|mut client| async move {
10081008
// no handshake
1009-
assert!(client
1010-
.prepare("select 1;".to_string(), None)
1011-
.await
1012-
.unwrap_err()
1013-
.to_string()
1014-
.contains("No authorization header"));
1009+
assert_contains(
1010+
client
1011+
.prepare("select 1;".to_string(), None)
1012+
.await
1013+
.unwrap_err()
1014+
.to_string(),
1015+
"No authorization header",
1016+
);
10151017

10161018
// Invalid credentials
1017-
assert!(client
1018-
.handshake("admin", "password2")
1019-
.await
1020-
.unwrap_err()
1021-
.to_string()
1022-
.contains("Invalid credentials"));
1019+
assert_contains(
1020+
client
1021+
.handshake("admin", "password2")
1022+
.await
1023+
.unwrap_err()
1024+
.to_string(),
1025+
"Invalid credentials",
1026+
);
10231027

10241028
// Invalid Tokens
10251029
client.handshake("admin", "password").await.unwrap();
10261030
client.set_token("wrong token".to_string());
1027-
assert!(client
1028-
.prepare("select 1;".to_string(), None)
1029-
.await
1030-
.unwrap_err()
1031-
.to_string()
1032-
.contains("invalid token"));
1031+
assert_contains(
1032+
client
1033+
.prepare("select 1;".to_string(), None)
1034+
.await
1035+
.unwrap_err()
1036+
.to_string(),
1037+
"invalid token",
1038+
);
10331039

10341040
client.clear_token();
10351041

@@ -1039,4 +1045,15 @@ mod tests {
10391045
})
10401046
.await
10411047
}
1048+
1049+
fn assert_contains(actual: impl AsRef<str>, searched_for: impl AsRef<str>) {
1050+
let actual = actual.as_ref();
1051+
let searched_for = searched_for.as_ref();
1052+
assert!(
1053+
actual.contains(searched_for),
1054+
"Expected '{}' to contain '{}'",
1055+
actual,
1056+
searched_for
1057+
);
1058+
}
10421059
}

0 commit comments

Comments
 (0)