Skip to content

Commit

Permalink
Add unit test for optional role_session_name
Browse files Browse the repository at this point in the history
  • Loading branch information
rquadling committed Nov 28, 2022
1 parent 719807e commit 1dc8d9b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/role_session_name_optional/expected_variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"assume_role_arn": {
"value": ""
},
"aws_cli_commands": {
"value": [
"s3api",
"list-objects",
"--bucket",
"ryft-public-sample-data",
"--no-sign-request"
]
},
"aws_cli_query": {
"value": "max_by(Contents, &Size)"
},
"debug_log_filename": {
"value": ""
},
"role_session_name": {
"value": ""
}
}
3 changes: 3 additions & 0 deletions tests/role_session_name_optional/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// ryft-public-sample-data is a publicly accessible S3 bucket.
aws_cli_commands = ["s3api", "list-objects", "--bucket", "ryft-public-sample-data", "--no-sign-request"]
aws_cli_query = "max_by(Contents, &Size)"
40 changes: 40 additions & 0 deletions tests/role_session_name_optional/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

function run_test() {
if [[ ! -f $PLAN_FILE ]]; then
echo "Failed to generate a plan - $PLAN_FILE";
exit 1;
fi

if [[ ! "$(terraform show -json $PLAN_FILE | jq -MSr .variables)" == "$(cat $EXPECTED_VARIABLES)" ]]; then
echo 'Failed to incorporate expected variable values into plan.';
exit 2;
fi

terraform apply -auto-approve -backup=- -state-out $STATE_FILE -var-file $TERRAFORM_TFVARS > $APPLY_LOG_FILE 2> $APPLY_ERROR_FILE

if [[ ! -f $STATE_FILE ]]; then
echo "Failed to generate state file - $STATE_FILE";
exit 3;
fi

# Extract some content the state file.
if [[ ! "$(cat $STATE_FILE)" == *'0ae8f910a30bc83fd81c4e3c1a6bbd9bab0afe4e0762b56a2807d22fcd77d517'* ]]; then
echo 'Failed to retrieve expected content from AWS.';
exit 4;
fi

# Extract some content from the apply log.
if [[ ! "$(cat $APPLY_LOG_FILE)" == *"0ae8f910a30bc83fd81c4e3c1a6bbd9bab0afe4e0762b56a2807d22fcd77d517"* ]]; then
echo 'Failed to present expected content to Terraform.';
exit 5;
fi

# Validate the absence of the debug log.
if [[ -f $DEBUG_LOG_FILE ]]; then
echo "Incorrectly generated debug.log file - $DEBUG_LOG_FILE";
exit 6;
fi
}

. tests/common.sh $0

0 comments on commit 1dc8d9b

Please sign in to comment.