Skip to content

Commit

Permalink
Add support for return ... blocks in acctest (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremmfr authored Jan 6, 2021
1 parent e32ee66 commit 7452f8e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The tool currently supports blocks with the following start and end lines:
|```terraform |`, |
|return fmt.Sprintf(`|`, |
|return fmt.Sprintf(`|`) |
|return ` |` |

### Extract Terraform Blocks

Expand Down
4 changes: 4 additions & 0 deletions lib/blocks/blockreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func ReaderIgnore(br *Reader, number int, line string) error {
func IsStartLine(line string) bool {
if strings.HasSuffix(line, "return fmt.Sprintf(`\n") { // acctest
return true
} else if strings.HasSuffix(line, "return `\n") { // acctest
return true
} else if strings.HasPrefix(line, "```hcl") { // documentation
return true
} else if strings.HasPrefix(line, "```terraform") { // documentation
Expand All @@ -78,6 +80,8 @@ func IsStartLine(line string) bool {
func IsFinishLine(line string) bool {
if accTestFinishLineWithLeadingSpacesMatcher.MatchString(line) { // acctest
return true
} else if strings.HasSuffix(line, "`\n") { // acctest
return true
} else if strings.HasPrefix(line, "```") { // documentation
return true
}
Expand Down
8 changes: 8 additions & 0 deletions lib/blocks/testdata/test1.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ resource "aws_s3_bucket" "simple" {
`)
}

func testReturnStringSimple() string {
return `
resource "aws_s3_bucket" "simple2" {
bucket = "tf-test-bucket-simple2"
}
`
}

func testReturnSprintfWithParameters(randInt int) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "with-parameters" {
Expand Down
4 changes: 4 additions & 0 deletions lib/blocks/testdata/test1_results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ expected_results:
resource "aws_s3_bucket" "simple" {
bucket = "tf-test-bucket-simple"
}
- |
resource "aws_s3_bucket" "simple2" {
bucket = "tf-test-bucket-simple2"
}
- |
resource "aws_s3_bucket" "with-parameters" {
bucket = "tf-test-bucket-with-parameters-%d"
Expand Down

0 comments on commit 7452f8e

Please sign in to comment.