Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for return ... blocks in acctest #39

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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