Skip to content

Commit

Permalink
- add unit test for the health check endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 committed Sep 18, 2024
1 parent fc442c1 commit a5e9081
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/core/http/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,39 @@ pub async fn handle_request<T: DeserializeOwned + GraphQLRequestLike>(

#[cfg(test)]
mod test {
use super::*;
use crate::core::async_graphql_hyper::GraphQLRequest;
use crate::core::blueprint::Blueprint;
use crate::core::config::{Config, ConfigModule};
use crate::core::rest::EndpointSet;
use crate::core::runtime::test::init;
use crate::core::valid::Validator;

#[tokio::test]
async fn test_health_endpoint() -> anyhow::Result<()> {
let sdl = tokio::fs::read_to_string(tailcall_fixtures::configs::JSONPLACEHOLDER).await?;
let config = Config::from_sdl(&sdl).to_result()?;
let blueprint = Blueprint::try_from(&ConfigModule::from(config))?;
let app_ctx = Arc::new(AppContext::new(
blueprint,
init(None),
EndpointSet::default(),
));

let req = Request::builder()
.method(Method::GET)
.uri("http://localhost:8000/status".to_string())
.body(Body::empty())?;

let resp = handle_request::<GraphQLRequest>(req, app_ctx).await?;

assert_eq!(resp.status(), StatusCode::OK);
let body = hyper::body::to_bytes(resp.into_body()).await?;
assert_eq!(body, r#"{"message": "ready"}"#);

Ok(())
}

#[test]
fn test_create_allowed_headers() {
use std::collections::BTreeSet;
Expand Down

0 comments on commit a5e9081

Please sign in to comment.