temporarily add no_run to middleware doctests (#626)

These test were failing because they made live requests to httpbin.org,
which is serving intermittent 500s.

In general we strive to make our test and doctests interact with a local
test server rather than a live website. For doctests we do this with
some sleight of hand in a hidden `ureq::is_test(true)`, which swaps out
the default agent returned by ureq::agent. However, since the middleware
doctests rely on constructing a custom agent with the middleware, they
can't rely on this.

I suspect we can get around this problem but it may take some thinking.

Similarly disable the AgentBuilder::user_agent and redirects doctests
and the agent_set_header unittest.
This commit is contained in:
Jacob Hoffman-Andrews
2023-06-13 23:00:26 -07:00
committed by GitHub
parent fbae1391ac
commit 905bf8f0b2
3 changed files with 27 additions and 26 deletions

View File

@@ -1,27 +1,28 @@
#[cfg(all(feature = "json", any(feature = "tls", feature = "tls-native")))]
#[test]
fn agent_set_header() {
use serde::Deserialize;
use std::collections::HashMap;
// test temporarily disabled because httpbin is down / we need to figure out
// how to eliminate the external dependency.
// #[test]
// fn agent_set_header() {
// use serde::Deserialize;
// use std::collections::HashMap;
#[derive(Deserialize, Debug)]
struct HttpBin {
headers: HashMap<String, String>,
}
let agent = ureq::Agent::new();
let resp = agent
.get("https://httpbin.org/get")
.set("header", "value")
.set("Connection", "close")
.call()
.unwrap();
assert_eq!(resp.status(), 200);
let json: HttpBin = resp.into_json().unwrap();
// println!("{:?}", json);
assert_eq!("value", json.headers.get("Header").unwrap());
}
// #[derive(Deserialize, Debug)]
// struct HttpBin {
// headers: HashMap<String, String>,
// }
// let agent = ureq::Agent::new();
// let resp = agent
// .get("https://httpbin.org/get")
// .set("header", "value")
// .set("Connection", "close")
// .call()
// .unwrap();
// assert_eq!(resp.status(), 200);
// let json: HttpBin = resp.into_json().unwrap();
// // println!("{:?}", json);
// assert_eq!("value", json.headers.get("Header").unwrap());
// }
#[test]
#[cfg(any(feature = "tls", feature = "tls-native"))]
// From here https://badssl.com/download/