Skip to content

Commit

Permalink
Merge pull request #46 from shogo82148/fix-fmt-diff-parser
Browse files Browse the repository at this point in the history
fix that tfnotify fmt reports incorrect result
  • Loading branch information
b4b4r07 authored Mar 13, 2020
2 parents f863e19 + 6b0ec9b commit b628a34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion terraform/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewDefaultParser() *DefaultParser {
// NewFmtParser is FmtParser initialized with its Regexp
func NewFmtParser() *FmtParser {
return &FmtParser{
Fail: regexp.MustCompile(`(?m)^(diff a/)`),
Fail: regexp.MustCompile(`(?m)^@@[^@]+@@`),
}
}

Expand Down
27 changes: 25 additions & 2 deletions terraform/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"testing"
)

const fmtSuccessResult = `
// terraform fmt -diff=true -write=false (version 0.11.x)
const fmtFailResult0_11 = `
google_spanner_database.tf
diff a/google_spanner_database.tf b/google_spanner_database.tf
--- /tmp/398669432
Expand All @@ -28,6 +29,19 @@ diff a/google_spanner_instance.tf b/google_spanner_instance.tf
+
`

// terraform fmt -diff=true -write=false (version 0.12.x)
const fmtFailResult0_12 = `
versions.tf
--- old/versions.tf
+++ new/versions.tf
@@ -1,4 +1,4 @@
terraform {
- required_version = ">= 0.12"
+ required_version = ">= 0.12"
}
`

const planSuccessResult = `
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
Expand Down Expand Up @@ -260,7 +274,16 @@ func TestFmtParserParse(t *testing.T) {
}{
{
name: "diff",
body: fmtSuccessResult,
body: fmtFailResult0_11,
result: ParseResult{
Result: "There is diff in your .tf file (need to be formatted)",
ExitCode: 1,
Error: nil,
},
},
{
name: "diff",
body: fmtFailResult0_12,
result: ParseResult{
Result: "There is diff in your .tf file (need to be formatted)",
ExitCode: 1,
Expand Down

0 comments on commit b628a34

Please sign in to comment.