Skip to content

Commit 1456b63

Browse files
committed
fix: improve readability of error assertions in request tests
1 parent 24e6dd2 commit 1456b63

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

crates/http-backend/src/lib.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,10 @@ mod tests {
943943

944944
// IPv6 with port
945945
assert_eq!(extract_host("[::1]:8080"), "::1");
946-
assert_eq!(extract_host("[2001:4860:4860::8888]:443"), "2001:4860:4860::8888");
946+
assert_eq!(
947+
extract_host("[2001:4860:4860::8888]:443"),
948+
"2001:4860:4860::8888"
949+
);
947950

948951
// IPv6 without port
949952
assert_eq!(extract_host("[::1]"), "::1");
@@ -969,7 +972,10 @@ mod tests {
969972
};
970973
let result = backend.make_request(req);
971974
assert!(result.is_err());
972-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
975+
assert!(result
976+
.unwrap_err()
977+
.to_string()
978+
.contains("private host not allowed"));
973979

974980
// Test private network
975981
let req = Request {
@@ -980,7 +986,10 @@ mod tests {
980986
};
981987
let result = backend.make_request(req);
982988
assert!(result.is_err());
983-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
989+
assert!(result
990+
.unwrap_err()
991+
.to_string()
992+
.contains("private host not allowed"));
984993

985994
// Test another private network
986995
let req = Request {
@@ -991,7 +1000,10 @@ mod tests {
9911000
};
9921001
let result = backend.make_request(req);
9931002
assert!(result.is_err());
994-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1003+
assert!(result
1004+
.unwrap_err()
1005+
.to_string()
1006+
.contains("private host not allowed"));
9951007

9961008
// Test link-local
9971009
let req = Request {
@@ -1002,7 +1014,10 @@ mod tests {
10021014
};
10031015
let result = backend.make_request(req);
10041016
assert!(result.is_err());
1005-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1017+
assert!(result
1018+
.unwrap_err()
1019+
.to_string()
1020+
.contains("private host not allowed"));
10061021
}
10071022

10081023
#[test]
@@ -1020,7 +1035,10 @@ mod tests {
10201035
};
10211036
let result = backend.make_request(req);
10221037
assert!(result.is_err());
1023-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1038+
assert!(result
1039+
.unwrap_err()
1040+
.to_string()
1041+
.contains("private host not allowed"));
10241042

10251043
// Test with Host header containing private IP with port
10261044
let req = Request {
@@ -1031,7 +1049,10 @@ mod tests {
10311049
};
10321050
let result = backend.make_request(req);
10331051
assert!(result.is_err());
1034-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1052+
assert!(result
1053+
.unwrap_err()
1054+
.to_string()
1055+
.contains("private host not allowed"));
10351056
}
10361057

10371058
#[test]
@@ -1049,7 +1070,10 @@ mod tests {
10491070
};
10501071
let result = backend.make_request(req);
10511072
assert!(result.is_err());
1052-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1073+
assert!(result
1074+
.unwrap_err()
1075+
.to_string()
1076+
.contains("private host not allowed"));
10531077

10541078
// Test unique local
10551079
let req = Request {
@@ -1060,7 +1084,10 @@ mod tests {
10601084
};
10611085
let result = backend.make_request(req);
10621086
assert!(result.is_err());
1063-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1087+
assert!(result
1088+
.unwrap_err()
1089+
.to_string()
1090+
.contains("private host not allowed"));
10641091

10651092
// Test link-local
10661093
let req = Request {
@@ -1071,7 +1098,10 @@ mod tests {
10711098
};
10721099
let result = backend.make_request(req);
10731100
assert!(result.is_err());
1074-
assert!(result.unwrap_err().to_string().contains("private host not allowed"));
1101+
assert!(result
1102+
.unwrap_err()
1103+
.to_string()
1104+
.contains("private host not allowed"));
10751105
}
10761106

10771107
#[test]
@@ -1136,6 +1166,4 @@ mod tests {
11361166
let result = backend.make_request(req);
11371167
assert!(result.is_ok());
11381168
}
1139-
1140-
11411169
}

0 commit comments

Comments
 (0)