Skip to content

Commit a94783a

Browse files
committed
Adding lambda test
1 parent c19ca9a commit a94783a

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Use this URL for the source of the module. See the usage examples below for more details.
88

99
```hcl
10-
github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=0.0.1
10+
github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=x.y.z
1111
```
1212

1313
### Alternative Installation Methods
@@ -26,7 +26,7 @@ Integrate this module like so:
2626

2727
```hcl
2828
module "elasticache-redis-standalone" {
29-
source = "github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=0.0.1"
29+
source = "github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=x.y.z"
3030
3131
# Tagging Parameters
3232
organization = var.organization
@@ -42,7 +42,7 @@ module "elasticache-redis-standalone" {
4242

4343
If this repo is added as a subtree, then the version of the module should be close to the version shown here:
4444

45-
`0.0.1`
45+
`x.y.z`
4646

4747
Note, however that subtrees can be altered as desired within repositories.
4848

examples/lambda/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ output "tags" {
3737
description = "The tags"
3838
value = module.redis.tags
3939
}
40+
41+
output "lambda_name" {
42+
description = "The name of the lambda function"
43+
value = module.lambda.name
44+
}

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ GIT_ROOT=$(git rev-parse --show-toplevel)
99
"$GIT_ROOT"/scripts/package.sh
1010

1111
pushd "$GIT_ROOT"/tests >/dev/null
12-
go test -timeout 30m -count=1 -parallel 10 ./...
12+
go test -timeout 45m -count=1 -parallel 10 ./...

tests/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import (
55
)
66

77
func TestBasicExample(t *testing.T) {
8-
testTemplate(t, "basic")
8+
testRedis(t, "basic")
99
}

tests/lambda_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestLambdaExample(t *testing.T) {
8+
testRedis(t, "lambda")
9+
}

tests/utilities_redis.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package test
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"strconv"
67
"testing"
78

9+
"github.com/aws/aws-sdk-go/aws/session"
10+
"github.com/aws/aws-sdk-go/service/lambda"
811
"github.com/gruntwork-io/terratest/modules/terraform"
912
"github.com/stretchr/testify/assert"
1013
)
1114

12-
func testTemplate(t *testing.T, variant string) {
15+
func testRedis(t *testing.T, variant string) {
1316
t.Parallel()
1417

1518
terraformDir := fmt.Sprintf("../examples/%s", variant)
@@ -50,4 +53,46 @@ func testTemplate(t *testing.T, variant string) {
5053
assert.Equal(t, expectedMemberClusters, memberClusters)
5154
assert.Contains(t, primaryEndpointAddress, expectedPartialPrimaryEndpointAddress)
5255
assert.Contains(t, readerEndpointAddress, expectedPartialReaderEndpointAddress)
56+
57+
if variant == "lambda" {
58+
expectedLambdaName := expectedName
59+
lambdaName := terraform.Output(t, terraformOptions, "lambda_name")
60+
assert.Equal(t, expectedLambdaName, lambdaName)
61+
62+
session, err := session.NewSession()
63+
if err != nil {
64+
t.Fatalf("Failed to create AWS session: %v", err)
65+
}
66+
67+
lambdaSvc := lambda.New(session)
68+
69+
invokeOutput, err := lambdaSvc.Invoke(&lambda.InvokeInput{
70+
FunctionName: &lambdaName,
71+
})
72+
73+
if err != nil {
74+
t.Fatal(err)
75+
}
76+
77+
var lambdaResp struct {
78+
Result string `json:"result"`
79+
Error string `json:"error"`
80+
}
81+
82+
err = json.Unmarshal(invokeOutput.Payload, &lambdaResp)
83+
84+
if err != nil {
85+
t.Fatal(err)
86+
}
87+
88+
if *invokeOutput.StatusCode != 200 {
89+
t.Logf("lambda response: %v", lambdaResp)
90+
t.Fatalf("Expected status code 200, got %d", *invokeOutput.StatusCode)
91+
}
92+
93+
if lambdaResp.Result == "failure" {
94+
t.Logf("lambda response: %v", lambdaResp)
95+
t.Fatalf("Expected result 'success', got 'failure'")
96+
}
97+
}
5398
}

0 commit comments

Comments
 (0)