From 7aa35487b2ffb394838b7368d6bc523deec4c1ec Mon Sep 17 00:00:00 2001 From: Rohit Sachdeva Date: Tue, 17 Sep 2024 12:52:22 -0500 Subject: [PATCH] Update test to use LocalStack for AWS deployments --- drive-deposits-check-cmd/Cargo.toml | 2 +- .../tests/test_delta_calculator_cli.rs | 24 +++++++++---------- justfile | 6 ++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drive-deposits-check-cmd/Cargo.toml b/drive-deposits-check-cmd/Cargo.toml index 41a03f2..26b0fa6 100644 --- a/drive-deposits-check-cmd/Cargo.toml +++ b/drive-deposits-check-cmd/Cargo.toml @@ -32,4 +32,4 @@ predicates = "3.1.0" #pretty_assertions = "1.4.0" [features] -aws_deploy = [] +localstack_aws_deploy = [] diff --git a/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs b/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs index 9331f40..9c6c41c 100644 --- a/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs +++ b/drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs @@ -1,15 +1,13 @@ use anyhow::Result; use assert_cmd::Command; +use enable_tracing::initialize_test_span; use predicates::prelude::predicate; use tracing::debug; -use enable_tracing::initialize_test_span; - mod enable_tracing; -// this test actually can be uncommented to check aws deploy works - -#[cfg(feature = "aws_deploy")] +// with event bridge aws deployment using localstack +#[cfg(feature = "localstack_aws_deploy")] #[test] fn test_portfolio_request_two_banks_json_valid() -> Result<()> { initialize_test_span("test_portfolio_request_two_banks_json_valid").in_scope(|| { @@ -20,19 +18,20 @@ fn test_portfolio_request_two_banks_json_valid() -> Result<()> { // "test=debug,drive_deposits_check_cmd=debug,drive_deposits_cal_types=debug", // ) // SEND_CAL_EVENTS = "true" - // only when manually want to test - can separate by environment for tests - // actually sends events to aws event bridge + // only when manually want to test + // actually sends events to localstack aws event bridge // test will fail if SEND_CAL_EVENTS is true and event bridge is not set up .env("SEND_CAL_EVENTS", "true") + .env("USE_LOCALSTACK", "true") .arg(json_request_file_path) .assert() .success(); - // let output = cmd.get_output(); - // debug!( - // "Command Stdout is: {}", - // String::from_utf8_lossy(&output.stdout) - // ); + let output = cmd.get_output(); + debug!( + "Command Stdout is: {}", + String::from_utf8_lossy(&output.stdout) + ); // // debug!( // "Command Stderr is: {}", @@ -52,6 +51,7 @@ fn test_portfolio_request_two_banks_json_valid() -> Result<()> { }) } +#[cfg(not(feature = "localstack_aws_deploy"))] #[test] fn test_portfolio_request_two_banks_json_invalid() -> Result<()> { initialize_test_span("portfolio_request_two_banks_json_invalid").in_scope(|| { diff --git a/justfile b/justfile index fbad200..0196df6 100644 --- a/justfile +++ b/justfile @@ -119,8 +119,8 @@ watch-run-drive-deposits-rest-gateway-server: test: cargo test --workspace -test-with-aws-deploy-only: - cargo test -p drive-deposits-check-cmd --test test_delta_calculator_cli --features aws_deploy -- test_portfolio_request_two_banks_json_valid --exact +test-localtsack-aws-deploy:localstack-deploy-drive-deposits-event-rules + cargo test -p drive-deposits-check-cmd --test test_delta_calculator_cli --features localstack_aws_deploy # watch test watch-test: @@ -519,7 +519,7 @@ localstack-build-drive-deposits-dynamodb-queries: localstack-deploy-drive-deposits-dynamodb-queries:localstack-deploy-drive-deposits-event-rules localstack-build-drive-deposits-dynamodb-queries echo "localstack deploy DriveDepositsByLevelLambdaReaderFunction" && \ cd drive-deposits-lambda-dynamodb-reader && \ - samlocal deploy --no-confirm-changeset --config-env dev --parameter-overrides UseLocalstack="true" Environment="dev" DriveDepositsTableName="drive-deposits-event-rules-dev-DRIVE-DEPOSITS-TABLE-NAME" + samlocal deploy --no-confirm-changeset --config-env dev --parameter-overrides UseLocalstack="true" Environment="dev" DriveDepositsTableName="drive-deposits-event-rules-dev-DRIVE-DEPOSITS-TABLE-NAME" || true # only this receipe for localstack # note localstack community version does not support apigwv2