This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a logging system based on Tracing
* Logs HTTP response data * Includes HTTP request information in log context * Can assert log lines during tests Note, this is not compatible with MozLog yet. ref #15
- Loading branch information
Showing
26 changed files
with
1,132 additions
and
226 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ adm: | |
remote_settings: | ||
storage_path: "./rs-cache" | ||
collection: "quicksuggest" | ||
|
||
logging: | ||
levels: [INFO] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,46 @@ | ||
//! Tests Merino's debug pages. | ||
#![cfg(test)] | ||
|
||
use crate::{merino_test, TestingTools}; | ||
use merino_settings::Settings; | ||
use reqwest::StatusCode; | ||
|
||
use crate::TestingTools; | ||
|
||
#[actix_rt::test] | ||
async fn cant_use_debug_settings_route_when_debug_is_false() { | ||
let TestingTools { test_client, .. } = TestingTools::new(|settings| settings.debug = false); | ||
|
||
let response = test_client | ||
.get("/debug/settings") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert_eq!(response.status(), StatusCode::NOT_FOUND); | ||
assert_eq!(response.content_length(), Some(0)); | ||
merino_test( | ||
|settings: &mut Settings| settings.debug = false, | ||
|TestingTools { test_client, .. }| async move { | ||
let response = test_client | ||
.get("/debug/settings") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert_eq!(response.status(), StatusCode::NOT_FOUND); | ||
assert_eq!(response.content_length(), Some(0)); | ||
}, | ||
) | ||
.await | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn can_use_debug_settings_route_when_debug_is_true() { | ||
let TestingTools { test_client, .. } = TestingTools::new(|settings| { | ||
settings.debug = true; | ||
}); | ||
|
||
let response = test_client | ||
.get("/debug/settings") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert_eq!( | ||
response.headers().get("content-type").unwrap(), | ||
&"application/json" | ||
); | ||
assert!(response.json::<serde_json::Value>().await.is_ok()); | ||
merino_test( | ||
|settings: &mut Settings| settings.debug = true, | ||
|TestingTools { test_client, .. }| async move { | ||
let response = test_client | ||
.get("/debug/settings") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert_eq!( | ||
response.headers().get("content-type").unwrap(), | ||
&"application/json" | ||
); | ||
assert!(response.json::<serde_json::Value>().await.is_ok()); | ||
}, | ||
) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,108 @@ | ||
//! Tests that Merino conforms to [Dockerflow](https://github.com/mozilla-services/dockerflow). | ||
#![cfg(test)] | ||
|
||
use crate::{merino_test, TestingTools}; | ||
use anyhow::Result; | ||
use reqwest::StatusCode; | ||
use serde::Deserialize; | ||
|
||
use crate::TestingTools; | ||
|
||
#[actix_rt::test] | ||
async fn lbheartbeat_works() { | ||
let TestingTools { test_client, .. } = TestingTools::new(|_| ()); | ||
|
||
let response = test_client | ||
.get("/__lbheartbeat__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert_eq!(response.content_length(), Some(0)); | ||
merino_test( | ||
|_| (), | ||
|TestingTools { test_client, .. }| async move { | ||
let response = test_client | ||
.get("/__lbheartbeat__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert_eq!(response.content_length(), Some(0)); | ||
}, | ||
) | ||
.await | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn heartbeat_works() -> Result<()> { | ||
let TestingTools { test_client, .. } = TestingTools::new(|_| ()); | ||
|
||
let response = test_client | ||
.get("/__heartbeat__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert!(response.status().is_success()); | ||
assert_eq!( | ||
response | ||
.headers() | ||
.get_all("content-type") | ||
.iter() | ||
.collect::<Vec<_>>(), | ||
vec!["application/json"] | ||
); | ||
Ok(()) | ||
merino_test( | ||
|_| (), | ||
|TestingTools { test_client, .. }| async move { | ||
let response = test_client | ||
.get("/__heartbeat__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert!(response.status().is_success()); | ||
assert_eq!( | ||
response | ||
.headers() | ||
.get_all("content-type") | ||
.iter() | ||
.collect::<Vec<_>>(), | ||
vec!["application/json"] | ||
); | ||
Ok(()) | ||
}, | ||
) | ||
.await | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn version_works() -> Result<()> { | ||
let TestingTools { test_client, .. } = TestingTools::new(|_| ()); | ||
|
||
let response = test_client | ||
.get("/__version__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert!(response.status().is_success()); | ||
assert_eq!( | ||
response | ||
.headers() | ||
.get_all("content-type") | ||
.iter() | ||
.collect::<Vec<_>>(), | ||
vec!["application/json"] | ||
); | ||
|
||
#[derive(Deserialize, Debug)] | ||
#[allow(dead_code)] | ||
struct VersionInfo { | ||
source: String, | ||
version: String, | ||
commit: String, | ||
build: String, | ||
} | ||
let body: Result<VersionInfo, _> = response.json().await; | ||
assert!(body.is_ok()); | ||
|
||
Ok(()) | ||
merino_test( | ||
|_| (), | ||
|TestingTools { test_client, .. }| async move { | ||
let response = test_client | ||
.get("/__version__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert!(response.status().is_success()); | ||
assert_eq!( | ||
response | ||
.headers() | ||
.get_all("content-type") | ||
.iter() | ||
.collect::<Vec<_>>(), | ||
vec!["application/json"] | ||
); | ||
|
||
#[derive(Deserialize, Debug)] | ||
#[allow(dead_code)] | ||
struct VersionInfo { | ||
source: String, | ||
version: String, | ||
commit: String, | ||
build: String, | ||
} | ||
let body: Result<VersionInfo, _> = response.json().await; | ||
assert!(body.is_ok()); | ||
|
||
Ok(()) | ||
}, | ||
) | ||
.await | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn error_works() -> Result<()> { | ||
let TestingTools { test_client, .. } = TestingTools::new(|_| ()); | ||
|
||
let response = test_client | ||
.get("/__error__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert!(response.status().is_server_error()); | ||
|
||
Ok(()) | ||
merino_test( | ||
|_| (), | ||
|TestingTools { test_client, .. }| async move { | ||
let response = test_client | ||
.get("/__error__") | ||
.send() | ||
.await | ||
.expect("failed to execute request"); | ||
|
||
assert!(response.status().is_server_error()); | ||
|
||
Ok(()) | ||
}, | ||
) | ||
.await | ||
} |
Oops, something went wrong.