about summary refs log tree commit diff
path: root/src/tests.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T21·22+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T22·10+0100
commit3530baa4d00c3b355f3f3a8a8cb6fd47489db83a (patch)
tree09daa70e1e367a04b2c59fa91cc22afcb377a22c /src/tests.rs
parente4e931661b23d1af41b97df3f17f937cd68cc77e (diff)
refactor: Add a method per HTTP verb on `Request`
Instead of the `Request::new` "constructor" for requests, add a method
per HTTP verb which makes the initialisation slightly more concise.
Diffstat (limited to 'src/tests.rs')
-rw-r--r--src/tests.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/tests.rs b/src/tests.rs
index 3b7a59cadd77..bc22b95fcac3 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -6,7 +6,7 @@ use serde_json::{Value, json};
 
 #[test]
 fn test_http_get() {
-    let resp = Request::new(Method::Get, "https://httpbin.org/get")
+    let resp = Request::get("https://httpbin.org/get")
         .send().expect("failed to send request");
 
     assert!(resp.is_success(), "request should have succeeded");
@@ -14,7 +14,7 @@ fn test_http_get() {
 
 #[test]
 fn test_http_delete() {
-    let resp = Request::new(Method::Delete, "https://httpbin.org/delete")
+    let resp = Request::delete("https://httpbin.org/delete")
         .send().expect("failed to send request");
 
     assert_eq!(200, resp.status, "response status should be 200 OK");
@@ -22,7 +22,7 @@ fn test_http_delete() {
 
 #[test]
 fn test_http_put() {
-    let resp = Request::new(Method::Put, "https://httpbin.org/put")
+    let resp = Request::put("https://httpbin.org/put")
         .send().expect("failed to send request");
 
     assert_eq!(200, resp.status, "response status should be 200 OK");
@@ -30,7 +30,7 @@ fn test_http_put() {
 
 #[test]
 fn test_http_patch() {
-    let resp = Request::new(Method::Patch, "https://httpbin.org/patch")
+    let resp = Request::patch("https://httpbin.org/patch")
         .send().expect("failed to send request");
 
     assert_eq!(200, resp.status, "response status should be 200 OK");
@@ -42,7 +42,7 @@ fn test_http_patch() {
 #[test]
 fn test_http_post() {
     let body = "test body";
-    let response = Request::new(Method::Post, "https://httpbin.org/post")
+    let response = Request::post("https://httpbin.org/post")
         .user_agent("crimp test suite").expect("failed to set user-agent")
         .timeout(Duration::from_secs(5)).expect("failed to set request timeout")
         .body("text/plain", &body.as_bytes())
@@ -69,7 +69,7 @@ fn test_http_post_json() {
         "purpose": "testing!"
     });
 
-    let response = Request::new(Method::Post, "https://httpbin.org/post")
+    let response = Request::post("https://httpbin.org/post")
         .user_agent("crimp test suite").expect("failed to set user-agent")
         .timeout(Duration::from_secs(5)).expect("failed to set request timeout")
         .json(&body).expect("request serialization failed")
@@ -96,7 +96,7 @@ fn test_http_post_json() {
 
 #[test]
 fn test_bearer_auth() {
-    let response = Request::new(Method::Get, "https://httpbin.org/bearer")
+    let response = Request::get("https://httpbin.org/bearer")
         .bearer_auth("some-token").expect("failed to set auth header")
         .send().expect("failed to send request");
 
@@ -105,9 +105,7 @@ fn test_bearer_auth() {
 
 #[test]
 fn test_basic_auth() {
-    let request = Request::new(
-        Method::Get, "https://httpbin.org/basic-auth/alan_watts/oneness"
-    );
+    let request = Request::get("https://httpbin.org/basic-auth/alan_watts/oneness");
 
     let response = request
         .basic_auth("alan_watts", "oneness").expect("failed to set auth header")
@@ -120,7 +118,7 @@ fn test_basic_auth() {
 
 #[test]
 fn test_error_for_status() {
-    let response = Request::new(Method::Get, "https://httpbin.org/patch")
+    let response = Request::get("https://httpbin.org/patch")
         .send().expect("failed to send request")
         .error_for_status(|resp| format!("Response error code: {}", resp.status));