diff options
author | Vincent Ambo <mail@tazj.in> | 2019-02-26T15·16+0100 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2019-02-26T16·30+0100 |
commit | d3a47d3b1c97fdd3497dd79ce66724876c383d12 (patch) | |
tree | 58c406670e2c80e48eb5fd42ee72f6b7b7f30d3c /src/tests.rs | |
parent | 9ce0098bc02ba385c0fc28651fd67a9c0c15c51d (diff) |
refactor: Move URL & method configuration to send()
This lets the builder proceed without returning a `Result` from the initial call, which makes for a slightly nicer API.
Diffstat (limited to 'src/tests.rs')
-rw-r--r-- | src/tests.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/tests.rs b/src/tests.rs index f4e3a393eaae..8067e7cf66e4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -7,9 +7,7 @@ use serde_json::{Value, json}; #[test] fn test_http_get() { let resp = Request::new(Method::Get, "https://httpbin.org/get") - .expect("failed to create request") - .send() - .expect("failed to send request"); + .send().expect("failed to send request"); assert_eq!(200, resp.status, "response status should be 200 OK"); } @@ -17,7 +15,6 @@ fn test_http_get() { #[test] fn test_http_delete() { let resp = Request::new(Method::Delete, "https://httpbin.org/delete") - .expect("failed to create request") .send().expect("failed to send request"); assert_eq!(200, resp.status, "response status should be 200 OK"); @@ -26,7 +23,6 @@ fn test_http_delete() { #[test] fn test_http_put() { let resp = Request::new(Method::Put, "https://httpbin.org/put") - .expect("failed to create request") .send().expect("failed to send request"); assert_eq!(200, resp.status, "response status should be 200 OK"); @@ -35,17 +31,18 @@ fn test_http_put() { #[test] fn test_http_patch() { let resp = Request::new(Method::Patch, "https://httpbin.org/patch") - .expect("failed to create request") .send().expect("failed to send request"); assert_eq!(200, resp.status, "response status should be 200 OK"); } +// These tests perform various requests with different body payloads +// and verify that those were received correctly by the remote side. + #[test] fn test_http_post() { let body = "test body"; let response = Request::new(Method::Post, "https://httpbin.org/post") - .expect("failed to create request") .user_agent("crimp test suite").expect("failed to set user-agent") .body("text/plain", &body.as_bytes()) .send().expect("failed to send request") @@ -65,14 +62,13 @@ fn test_http_post() { ); } -#[test] +#[cfg(feature = "json")] #[test] fn test_http_post_json() { let body = json!({ "purpose": "testing!" }); let response = Request::new(Method::Post, "https://httpbin.org/post") - .expect("failed to create request") .user_agent("crimp test suite").expect("failed to set user-agent") .json(&body).expect("request serialization failed") .send().expect("failed to send request") |