Skip to content

Commit

Permalink
update: introducing assert_matches! in Da job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Jul 31, 2024
1 parent 7c1e3a1 commit ac086d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ with_mongodb = ["mongodb"]
with_sqs = ["omniqueue"]

[dev-dependencies]
assert_matches = "1.5.0"
hyper = { version = "0.14", features = ["full"] }
rstest = { workspace = true }
httpmock = { workspace = true, features = ["remote"] }
33 changes: 16 additions & 17 deletions crates/orchestrator/src/tests/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::jobs::types::{ExternalId, JobItem, JobStatus, JobType};
use crate::tests::common::drop_database;
use crate::tests::config::TestConfigBuilder;
use crate::{config::config, jobs::Job};
use assert_matches::assert_matches;
use color_eyre::{eyre::eyre, Result};
use da_client_interface::MockDaClient;
use mockall::predicate::always;
Expand Down Expand Up @@ -84,23 +85,20 @@ async fn test_da_job_process_job_failure_on_small_blob_size(
)
.await;

match response {
Ok(_) => {
panic!("This test's process_job was supposed to throw an error, it succeeded instead.")
}
assert_matches!(response,
Err(e) => {
let expected = eyre!(
let expected_error = eyre!(
"Exceeded the maximum number of blobs per transaction: allowed {}, found {} for block {} and job id {}",
max_blob_per_txn,
current_blob_length,
internal_id.to_string(),
Uuid::default()
)
.to_string();

assert_eq!(e.to_string(), expected);
assert_eq!(e.to_string(), expected_error);
}
}
);

state_update_mock.assert();
let _ = drop_database().await;
}
Expand Down Expand Up @@ -151,19 +149,18 @@ async fn test_da_job_process_job_failure_on_pending_block() {
)
.await;

match response {
Ok(_) => panic!("This testcase should not have processed the job correctly."),
assert_matches!(response,
Err(e) => {
let expected = eyre!(
let expected_error = eyre!(
"Cannot process block {} for job id {} as it's still in pending state",
internal_id.to_string(),
Uuid::default()
)
.to_string();

assert_eq!(e.to_string(), expected);
assert_eq!(e.to_string(), expected_error);
}
}
);

state_update_mock.assert();
}

Expand Down Expand Up @@ -229,9 +226,11 @@ async fn test_da_job_process_job_success(
)
.await;

if let Ok(message) = response {
assert_eq!(message, eyre!("Done").to_string());
}
assert_matches!(response,
Ok(msg) => {
assert_eq!(msg, eyre!("Done").to_string());
}
);

state_update_mock.assert();
let _ = drop_database().await;
Expand Down

0 comments on commit ac086d7

Please sign in to comment.