Skip to content

Commit

Permalink
add sweeper for lambda functions
Browse files Browse the repository at this point in the history
  • Loading branch information
catsby committed Sep 25, 2017
1 parent ee2f0b8 commit b0a52c7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions aws/import_aws_lambda_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,64 @@ package aws

import (
"fmt"
"log"
"strings"
"testing"

"github.com/aws/aws-sdk-go/service/lambda"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func init() {
resource.AddTestSweepers("aws_lambda_function", &resource.Sweeper{
Name: "aws_lambda_function",
F: testSweepLambdaFunctions,
})
}

func testSweepLambdaFunctions(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

lambdaconn := client.(*AWSClient).lambdaconn

resp, err := lambdaconn.ListFunctions(&lambda.ListFunctionsInput{})
if err != nil {
return fmt.Errorf("Error retrieving Lambda functions: %s", err)
}

if len(resp.Functions) == 0 {
log.Print("[DEBUG] No aws lambda functions to sweep")
return nil
}

for _, f := range resp.Functions {
var testOptGroup bool
for _, testName := range []string{"tf_test"} {
if strings.HasPrefix(*f.FunctionName, testName) {
testOptGroup = true
}
}

if !testOptGroup {
continue
}

_, err := lambdaconn.DeleteFunction(
&lambda.DeleteFunctionInput{
FunctionName: f.FunctionName,
})
if err != nil {
return err
}
}

return nil
}

func TestAccAWSLambdaFunction_importLocalFile(t *testing.T) {
resourceName := "aws_lambda_function.lambda_function_test"

Expand Down

0 comments on commit b0a52c7

Please sign in to comment.