#[cfg(feature = "proxy")]
mod http_connect {
#[test]
fn http_200_is_ok() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 200 Connection established\r\n\r\n"
);
assert!(result.is_ok(), "200 should succeed, got {result:?}");
}
#[test]
fn http_200_bare_ok() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.0 200 OK\r\n\r\n"
);
assert!(result.is_ok());
}
#[test]
fn http_201_is_ok() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 201 Created\r\n\r\n"
);
assert!(result.is_ok());
}
#[test]
fn http_407_proxy_auth_required_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 407 Proxy Authentication Required\r\n\r\n"
);
assert!(result.is_err());
let msg = result.unwrap_err().to_string();
assert!(msg.contains("407"), "error should mention 407, got: {msg}");
}
#[test]
fn http_403_forbidden_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 403 Forbidden\r\n\r\n"
);
assert!(result.is_err());
}
#[test]
fn http_502_bad_gateway_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 502 Bad Gateway\r\n\r\n"
);
assert!(result.is_err());
let msg = result.unwrap_err().to_string();
assert!(msg.contains("502"));
}
#[test]
fn http_503_service_unavailable_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 503 Service Unavailable\r\n\r\n"
);
assert!(result.is_err());
}
#[test]
fn empty_response_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test("");
assert!(result.is_err());
}
#[test]
fn response_without_status_code_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 \r\n\r\n"
);
assert!(result.is_err());
}
#[test]
fn non_http_response_is_error() {
let result = rust_mc_status::proxy::http::validate_response_test(
"\x00\x01\x02\x03"
);
assert!(result.is_err());
}
#[test]
fn error_message_contains_status_code() {
let result = rust_mc_status::proxy::http::validate_response_test(
"HTTP/1.1 407 Proxy Auth Required\r\n\r\n"
);
let msg = result.unwrap_err().to_string();
assert!(msg.contains("407"), "msg should contain 407: {msg}");
assert!(msg.contains("Proxy Auth Required"), "msg should contain reason: {msg}");
}
}