add tests

This commit is contained in:
qdequele 2020-05-07 15:15:18 +02:00
parent 71e3b5bc11
commit f2b7aea16c
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
2 changed files with 23 additions and 4 deletions

View File

@ -7,6 +7,7 @@ use actix_web::{http::StatusCode, test};
use meilisearch_core::DatabaseOptions; use meilisearch_core::DatabaseOptions;
use meilisearch_http::data::Data; use meilisearch_http::data::Data;
use meilisearch_http::option::Opt; use meilisearch_http::option::Opt;
use meilisearch_http::helpers::NormalizeSlashes;
use tempdir::TempDir; use tempdir::TempDir;
use tokio::time::delay_for; use tokio::time::delay_for;
@ -126,7 +127,7 @@ impl Server {
pub async fn get_request(&mut self, url: &str) -> (Value, StatusCode) { pub async fn get_request(&mut self, url: &str) -> (Value, StatusCode) {
eprintln!("get_request: {}", url); eprintln!("get_request: {}", url);
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await;
let req = test::TestRequest::get().uri(url).to_request(); let req = test::TestRequest::get().uri(url).to_request();
let res = test::call_service(&mut app, req).await; let res = test::call_service(&mut app, req).await;
@ -140,7 +141,7 @@ impl Server {
pub async fn post_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) { pub async fn post_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
eprintln!("post_request: {}", url); eprintln!("post_request: {}", url);
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await;
let req = test::TestRequest::post() let req = test::TestRequest::post()
.uri(url) .uri(url)
@ -169,7 +170,7 @@ impl Server {
pub async fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) { pub async fn put_request(&mut self, url: &str, body: Value) -> (Value, StatusCode) {
eprintln!("put_request: {}", url); eprintln!("put_request: {}", url);
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await;
let req = test::TestRequest::put() let req = test::TestRequest::put()
.uri(url) .uri(url)
@ -197,7 +198,7 @@ impl Server {
pub async fn delete_request(&mut self, url: &str) -> (Value, StatusCode) { pub async fn delete_request(&mut self, url: &str) -> (Value, StatusCode) {
eprintln!("delete_request: {}", url); eprintln!("delete_request: {}", url);
let mut app = test::init_service(meilisearch_http::create_app(&self.data)).await; let mut app = test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizeSlashes)).await;
let req = test::TestRequest::delete().uri(url).to_request(); let req = test::TestRequest::delete().uri(url).to_request();
let res = test::call_service(&mut app, req).await; let res = test::call_service(&mut app, req).await;

View File

@ -0,0 +1,18 @@
mod common;
#[actix_rt::test]
async fn url_normalizer() {
let mut server = common::Server::with_uid("movies");
let (_response, status_code) = server.get_request("/version").await;
assert_eq!(status_code, 200);
let (_response, status_code) = server.get_request("//version").await;
assert_eq!(status_code, 200);
let (_response, status_code) = server.get_request("/version/").await;
assert_eq!(status_code, 200);
let (_response, status_code) = server.get_request("//version/").await;
assert_eq!(status_code, 200);
}