Skip to content

Commit 3f50803

Browse files
committed
tests: scaffolding for integration tests
1 parent f233dd2 commit 3f50803

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

tests/integration.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Scaffolding for integration tests.
2+
//!
3+
//! ```text
4+
//! cargo test --test integration
5+
//! ```
6+
mod servers;
7+
8+
// todo: there is only one test example that was copied from other package.
9+
// We have to add tests for the whole app.
10+
11+
use torrust_tracker_clock::clock;
12+
13+
/// This code needs to be copied into each crate.
14+
/// Working version, for production.
15+
#[cfg(not(test))]
16+
#[allow(dead_code)]
17+
pub(crate) type CurrentClock = clock::Working;
18+
19+
/// Stopped version, for testing.
20+
#[cfg(test)]
21+
#[allow(dead_code)]
22+
pub(crate) type CurrentClock = clock::Stopped;

tests/servers/health_check_api.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use reqwest::Response;
2+
use torrust_axum_health_check_api_server::environment::Started;
3+
use torrust_axum_health_check_api_server::resources::{Report, Status};
4+
use torrust_server_lib::registar::Registar;
5+
use torrust_tracker_test_helpers::{configuration, logging};
6+
7+
pub async fn get(path: &str) -> Response {
8+
reqwest::Client::builder().build().unwrap().get(path).send().await.unwrap()
9+
}
10+
11+
#[tokio::test]
12+
async fn the_health_check_endpoint_should_return_status_ok_when_there_is_not_any_service_registered() {
13+
logging::setup();
14+
15+
let configuration = configuration::ephemeral_with_no_services();
16+
17+
let env = Started::new(&configuration.health_check_api.into(), Registar::default()).await;
18+
19+
let response = get(&format!("http://{}/health_check", env.state.binding)).await; // DevSkim: ignore DS137138
20+
21+
assert_eq!(response.status(), 200);
22+
assert_eq!(response.headers().get("content-type").unwrap(), "application/json");
23+
24+
let report = response
25+
.json::<Report>()
26+
.await
27+
.expect("it should be able to get the report as json");
28+
29+
assert_eq!(report.status, Status::None);
30+
31+
env.stop().await.expect("it should stop the service");
32+
}

tests/servers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod health_check_api;

0 commit comments

Comments
 (0)