(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestHCL2Formatter_Format(t *testing.T) { |
| 17 | tt := []struct { |
| 18 | Name string |
| 19 | Paths []string |
| 20 | FormatExpected bool |
| 21 | }{ |
| 22 | {Name: "Unformatted file", Paths: []string{"testdata/format/unformatted.pkr.hcl"}, FormatExpected: true}, |
| 23 | {Name: "Unformatted vars file", Paths: []string{"testdata/format/unformatted.pkrvars.hcl"}, FormatExpected: true}, |
| 24 | {Name: "Formatted file", Paths: []string{"testdata/format/formatted.pkr.hcl"}}, |
| 25 | {Name: "Directory", Paths: []string{"testdata/format"}, FormatExpected: true}, |
| 26 | {Name: "No file", Paths: []string{}, FormatExpected: false}, |
| 27 | {Name: "Multi File", Paths: []string{"testdata/format/unformatted.pkr.hcl", "testdata/format/unformatted.pkrvars.hcl"}, FormatExpected: true}, |
| 28 | } |
| 29 | |
| 30 | for _, tc := range tt { |
| 31 | tc := tc |
| 32 | var buf bytes.Buffer |
| 33 | f := NewHCL2Formatter() |
| 34 | f.Output = &buf |
| 35 | _, diags := f.Format(tc.Paths) |
| 36 | if diags.HasErrors() { |
| 37 | t.Fatalf("the call to Format failed unexpectedly %s", diags.Error()) |
| 38 | } |
| 39 | if buf.String() != "" && tc.FormatExpected == false { |
| 40 | t.Errorf("Format(%q) should contain the name of the formatted file(s), but got %q", tc.Paths, buf.String()) |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func TestHCL2Formatter_Format_Write(t *testing.T) { |
| 46 |
nothing calls this directly
no test coverage detected
searching dependent graphs…