Skip to content

Commit

Permalink
feat(jstzd): update
Browse files Browse the repository at this point in the history
  • Loading branch information
huancheng-trili committed Sep 18, 2024
1 parent ebb5019 commit fec2a4f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/jstzd/src/task/octez_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,25 @@ mod tests {
}
pub async fn get(url: String) -> anyhow::Result<MockBody> {
if url.contains("success") {
// Simulating a normal and expected response from the health check endpoint
anyhow::Ok(MockBody {
res: HashMap::from([("ready".to_owned(), true)]),
bad_json: false,
})
} else if url.contains("server_error") {
// Simulating the case where the server is not accessible or
// returns a 4xx/5xx code
Err(anyhow::anyhow!("server error"))
} else if url.contains("json_error") {
// Simulating the case where the health check endpoint response cannot
// be deserialised correctly
anyhow::Ok(MockBody {
res: HashMap::new(),
bad_json: true,
})
} else {
// Simulating the case where the health check endpoint does not return the
// expected data and thus the health check method cannot capture the information
anyhow::Ok(MockBody {
res: HashMap::new(),
bad_json: false,
Expand Down Expand Up @@ -319,6 +326,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn health_check_ready() {
// Test if the method identifies a healthy service
let f = OctezNode::spawn(OctezNodeConfig::new(
"/tmp/binary",
"/tmp/something",
Expand All @@ -335,6 +343,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn health_check_server_error() {
// Test if the method handles 4xx/5xx errors from the health check endpoint
let f = OctezNode::spawn(OctezNodeConfig::new(
"/tmp/binary",
"/tmp/something",
Expand All @@ -351,6 +360,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn health_check_json_error() {
// Test if the method handles bad data deserialisation
let f = OctezNode::spawn(OctezNodeConfig::new(
"/tmp/binary",
"/tmp/something",
Expand All @@ -370,6 +380,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn health_check_body_error() {
// Test if the method handles unexpected health check information
let f = OctezNode::spawn(OctezNodeConfig::new(
"/tmp/binary",
"/tmp/something",
Expand Down

0 comments on commit fec2a4f

Please sign in to comment.