From 6a742ee62c250a0108ef6706c9c52b462b3a2c8f Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 15 Mar 2021 19:08:19 +0100 Subject: [PATCH] restore version route --- Cargo.lock | 2 +- meilisearch-http/Cargo.toml | 2 +- meilisearch-http/src/routes/stats.rs | 6 +++++- meilisearch-http/tests/common/server.rs | 4 ++++ meilisearch-http/tests/integration.rs | 1 + meilisearch-http/tests/stats/mod.rs | 12 ++++++++++++ 6 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 meilisearch-http/tests/stats/mod.rs diff --git a/Cargo.lock b/Cargo.lock index bcdcec71c..dd0531ae3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1786,7 +1786,7 @@ dependencies = [ [[package]] name = "meilisearch-http" -version = "0.17.0" +version = "0.21.0-alpha" dependencies = [ "actix-cors", "actix-http 3.0.0-beta.4", diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index 9ae7baae2..f417d4391 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -4,7 +4,7 @@ description = "MeiliSearch HTTP server" edition = "2018" license = "MIT" name = "meilisearch-http" -version = "0.17.0" +version = "0.21.0-alpha" [[bin]] name = "meilisearch" path = "src/main.rs" diff --git a/meilisearch-http/src/routes/stats.rs b/meilisearch-http/src/routes/stats.rs index eee6536c6..172b5dde9 100644 --- a/meilisearch-http/src/routes/stats.rs +++ b/meilisearch-http/src/routes/stats.rs @@ -56,5 +56,9 @@ struct VersionResponse { #[get("/version", wrap = "Authentication::Private")] async fn get_version() -> HttpResponse { - todo!() + HttpResponse::Ok().json(VersionResponse { + commit_sha: env!("VERGEN_SHA").to_string(), + build_date: env!("VERGEN_BUILD_TIMESTAMP").to_string(), + pkg_version: env!("CARGO_PKG_VERSION").to_string(), + }) } diff --git a/meilisearch-http/tests/common/server.rs b/meilisearch-http/tests/common/server.rs index 6c7225a8f..43caf1dc6 100644 --- a/meilisearch-http/tests/common/server.rs +++ b/meilisearch-http/tests/common/server.rs @@ -69,4 +69,8 @@ impl Server { pub async fn list_indexes(&self) -> (Value, StatusCode) { self.service.get("/indexes").await } + + pub async fn version(&self) -> (Value, StatusCode) { + self.service.get("/version").await + } } diff --git a/meilisearch-http/tests/integration.rs b/meilisearch-http/tests/integration.rs index 7578a8dc1..8acc75ff9 100644 --- a/meilisearch-http/tests/integration.rs +++ b/meilisearch-http/tests/integration.rs @@ -4,6 +4,7 @@ mod index; mod search; mod settings; mod updates; +mod stats; // Tests are isolated by features in different modules to allow better readability, test // targetability, and improved incremental compilation times. diff --git a/meilisearch-http/tests/stats/mod.rs b/meilisearch-http/tests/stats/mod.rs new file mode 100644 index 000000000..733e2ba79 --- /dev/null +++ b/meilisearch-http/tests/stats/mod.rs @@ -0,0 +1,12 @@ +use crate::common::Server; + +#[actix_rt::test] +async fn get_settings_unexisting_index() { + let server = Server::new().await; + let (response, code) = server.version().await; + assert_eq!(code, 200); + let version = response.as_object().unwrap(); + assert!(version.get("commitSha").is_some()); + assert!(version.get("buildDate").is_some()); + assert!(version.get("pkgVersion").is_some()); +}