Skip to content

Commit

Permalink
Update test to use LocalStack for AWS deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
rsachdeva committed Sep 17, 2024
1 parent 443f4a9 commit 7aa3548
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion drive-deposits-check-cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ predicates = "3.1.0"
#pretty_assertions = "1.4.0"

[features]
aws_deploy = []
localstack_aws_deploy = []
24 changes: 12 additions & 12 deletions drive-deposits-check-cmd/tests/test_delta_calculator_cli.rs
Original file line number Diff line number Diff line change
@@ -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(|| {
Expand All @@ -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: {}",
Expand All @@ -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(|| {
Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7aa3548

Please sign in to comment.