about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-27T13·30+0100
committerVincent Ambo <github@tazj.in>2019-02-27T13·39+0100
commit951bc7ae8572452537cf6e0680c23e8b3b1afd52 (patch)
tree8365d55687275cebfafd06330fb6a60939ba7f64
parent67bfba446d42e047796c79046920caa5cdcd90f0 (diff)
refactor(tests): Use local httpbin instance in tests
Instead of relying on the external httpbin instance which is
occasionally wonky, use Docker to spin up a local instance in Travis
CI when testing.

This fixes #1.
-rw-r--r--.travis.yml6
-rw-r--r--src/tests.rs27
2 files changed, 23 insertions, 10 deletions
diff --git a/.travis.yml b/.travis.yml
index 5b0e032f1844..495c58250d05 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,2 +1,8 @@
 language: rust
 cache: cargo
+
+# Configure local httpbin instance:
+services:
+  - docker
+before_install:
+  - docker run -d -p 4662:80 kennethreitz/httpbin
diff --git a/src/tests.rs b/src/tests.rs
index a2bf1e7f5eb3..6c2bc4f5b37a 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1,12 +1,19 @@
+// All tests expect an httpbin instance to be available at
+// `http://localhost:4662`.
+//
+// This is easily spun up using Docker by running:
+//
+//    docker run --rm -p 4662:80 kennethreitz/httpbin
+
 use super::*;
 use serde_json::{Value, json};
 
 // These tests check whether the correct HTTP method is used in the
-// requests. httpbin will return 405-statuses for incorrect methods.
+// requests.
 
 #[test]
 fn test_http_get() {
-    let resp = Request::get("https://httpbin.org/get")
+    let resp = Request::get("http://127.0.0.1:4662/get")
         .send().expect("failed to send request");
 
     assert!(resp.is_success(), "request should have succeeded");
@@ -14,7 +21,7 @@ fn test_http_get() {
 
 #[test]
 fn test_http_delete() {
-    let resp = Request::delete("https://httpbin.org/delete")
+    let resp = Request::delete("http://127.0.0.1:4662/delete")
         .send().expect("failed to send request");
 
     assert_eq!(200, resp.status, "response status should be 200 OK");
@@ -22,7 +29,7 @@ fn test_http_delete() {
 
 #[test]
 fn test_http_put() {
-    let resp = Request::put("https://httpbin.org/put")
+    let resp = Request::put("http://127.0.0.1:4662/put")
         .send().expect("failed to send request");
 
     assert_eq!(200, resp.status, "response status should be 200 OK");
@@ -30,7 +37,7 @@ fn test_http_put() {
 
 #[test]
 fn test_http_patch() {
-    let resp = Request::patch("https://httpbin.org/patch")
+    let resp = Request::patch("http://127.0.0.1:4662/patch")
         .send().expect("failed to send request");
 
     assert_eq!(200, resp.status, "response status should be 200 OK");
@@ -42,7 +49,7 @@ fn test_http_patch() {
 #[test]
 fn test_http_post() {
     let body = "test body";
-    let response = Request::post("https://httpbin.org/post")
+    let response = Request::post("http://127.0.0.1:4662/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 +76,7 @@ fn test_http_post_json() {
         "purpose": "testing!"
     });
 
-    let response = Request::post("https://httpbin.org/post")
+    let response = Request::post("http://127.0.0.1:4662/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 +103,7 @@ fn test_http_post_json() {
 
 #[test]
 fn test_bearer_auth() {
-    let response = Request::get("https://httpbin.org/bearer")
+    let response = Request::get("http://127.0.0.1:4662/bearer")
         .bearer_auth("some-token").expect("failed to set auth header")
         .send().expect("failed to send request");
 
@@ -105,7 +112,7 @@ fn test_bearer_auth() {
 
 #[test]
 fn test_basic_auth() {
-    let request = Request::get("https://httpbin.org/basic-auth/alan_watts/oneness");
+    let request = Request::get("http://127.0.0.1:4662/basic-auth/alan_watts/oneness");
 
     let response = request
         .basic_auth("alan_watts", "oneness").expect("failed to set auth header")
@@ -136,7 +143,7 @@ fn test_large_body() {
 
 #[test]
 fn test_error_for_status() {
-    let response = Request::get("https://httpbin.org/patch")
+    let response = Request::get("http://127.0.0.1:4662/patch")
         .send().expect("failed to send request")
         .error_for_status(|resp| format!("Response error code: {}", resp.status));