Skip to content

Commit

Permalink
updating regexps in go test and updating unit test module code
Browse files Browse the repository at this point in the history
  • Loading branch information
haitchison committed Dec 20, 2023
1 parent bc304b7 commit a91e434
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions test/lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ func TestLambdaCreation(t *testing.T) {

checkSubnetId := terraform.Output(t, terraformOptions, "subnet_ids")
checkSecurityGroupId := terraform.Output(t, terraformOptions, "security_group_ids")
re := regexp.MustCompile(`[{}\[\]\s]`)
SubnetID = re.ReplaceAllString(checkSubnetID, "")
SecurityGroupID = re.ReplaceAllString(checkSecurityGroupID, "")

assert.Regexp(t, regexp.MustCompile(`^instance-scheduler-lambda-function*`), functionName)
assert.Regexp(t, regexp.MustCompile(`^200*`), resultCode)

assert.Regexp(t, regexp.MustCompile(`^subnet-\w+$`), checkSubnetId)
assert.Regexp(t, regexp.MustCompile(`^sg-\d+$`), checkSecurityGroupId)
assert.Regexp(t, regexp.MustCompile(`^subnet-\w+$`), SubnetId)
assert.Regexp(t, regexp.MustCompile(`^sg-\d+$`), SecurityGroupId)
}
6 changes: 4 additions & 2 deletions test/unit-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ data "aws_iam_policy_document" "AWSLambdaVPCAccessExecutionRole" {
statement {
sid = "AWSLambdaVPCAccessExecutionRole"
effect = "Allow"
resources = ["*"]

actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
Expand All @@ -100,6 +98,9 @@ data "aws_iam_policy_document" "AWSLambdaVPCAccessExecutionRole" {
"ec2:AssignPrivateIpAddresses",
"ec2:UnassignPrivateIpAddresses",
]
resources = [
format("arn:aws:logs:eu-west-2:%s:aws/lambda/fake", data.aws_caller_identity.current.account_id)
]
}
}

Expand Down Expand Up @@ -212,6 +213,7 @@ resource "aws_security_group" "lambda_security_group_test" {
vpc_id = data.aws_vpc.platforms-test.id

egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1"
Expand Down

0 comments on commit a91e434

Please sign in to comment.