MCPcopy
hub / github.com/hashicorp/packer / TestHCL2Formatter_Format

Function TestHCL2Formatter_Format

hcl2template/formatter_test.go:16–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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
45func TestHCL2Formatter_Format_Write(t *testing.T) {
46

Callers

nothing calls this directly

Calls 5

FormatMethod · 0.95
NewHCL2FormatterFunction · 0.85
ErrorMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…