From 116a637cfd2a4e0e4be9e225ad1175dab1769a2c Mon Sep 17 00:00:00 2001 From: qdequele Date: Wed, 15 Jan 2020 17:56:07 +0100 Subject: [PATCH] set test for healthyness --- meilisearch-http/Cargo.toml | 2 +- meilisearch-http/tests/health.rs | 48 +++++++++++++++++++++++ meilisearch-http/tests/index_creations.rs | 17 -------- 3 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 meilisearch-http/tests/health.rs delete mode 100644 meilisearch-http/tests/index_creations.rs diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index f7e8a1e2e..7655ac209 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -40,10 +40,10 @@ whoami = "0.6" tide = "0.5.1" async-std = { version = "1.0.1", features = ["unstable", "attributes"] } + [dev-dependencies] http-service-mock = "0.4.0" http-service = "0.4.0" - tempdir = "0.3.7" [build-dependencies] diff --git a/meilisearch-http/tests/health.rs b/meilisearch-http/tests/health.rs new file mode 100644 index 000000000..f41ee20c9 --- /dev/null +++ b/meilisearch-http/tests/health.rs @@ -0,0 +1,48 @@ +use http_service::Body; +use serde_json::json; +use std::convert::Into; + +mod common; + +#[test] +fn test_healthyness() { + let mut server = common::setup_server().unwrap(); + + // Check that the server is healthy + + let req = http::Request::get("/health").body(Body::empty()).unwrap(); + let res = server.simulate(req).unwrap(); + assert_eq!(res.status(), 200); + + // Set the serve Unhealthy + + let body = json!({ + "health": false, + }).to_string().into_bytes(); + + let req = http::Request::put("/health").body(Body::from(body)).unwrap(); + let res = server.simulate(req).unwrap(); + assert_eq!(res.status(), 200); + + // Check that the server is unhealthy + + let req = http::Request::get("/health").body(Body::empty()).unwrap(); + let res = server.simulate(req).unwrap(); + assert_eq!(res.status(), 503); + + // Set the server healthy + + let body = json!({ + "health": true, + }).to_string().into_bytes(); + + let req = http::Request::put("/health").body(Body::from(body)).unwrap(); + let res = server.simulate(req).unwrap(); + assert_eq!(res.status(), 200); + + // Check if the server is healthy + + let req = http::Request::get("/health").body(Body::empty()).unwrap(); + let res = server.simulate(req).unwrap(); + assert_eq!(res.status(), 200); +} diff --git a/meilisearch-http/tests/index_creations.rs b/meilisearch-http/tests/index_creations.rs deleted file mode 100644 index c8c212c60..000000000 --- a/meilisearch-http/tests/index_creations.rs +++ /dev/null @@ -1,17 +0,0 @@ -// use async_std::prelude::*; -// use async_std::task; -// use std::time::Duration; - -// use serde::{Deserialize, Serialize}; -use http_service::Body; - -mod common; - -#[test] -fn create_index() { - let mut server = common::setup_server().unwrap(); - - let req = http::Request::get("/health").body(Body::empty()).unwrap(); - let res = server.simulate(req).unwrap(); - assert_eq!(res.status(), 200); -}