From da699dac59b66f0287839d8ca2ffe9a9663da8fb Mon Sep 17 00:00:00 2001 From: anshul sharma Date: Fri, 25 Apr 2025 10:43:02 +0530 Subject: [PATCH] existing test code fix --- hcl2template/formatter_test.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hcl2template/formatter_test.go b/hcl2template/formatter_test.go index 8cb909292..ad88f6c4f 100644 --- a/hcl2template/formatter_test.go +++ b/hcl2template/formatter_test.go @@ -16,13 +16,13 @@ import ( func TestHCL2Formatter_Format(t *testing.T) { tt := []struct { Name string - Path string + Paths []string FormatExpected bool }{ - {Name: "Unformatted file", Path: "testdata/format/unformatted.pkr.hcl", FormatExpected: true}, - {Name: "Unformatted vars file", Path: "testdata/format/unformatted.pkrvars.hcl", FormatExpected: true}, - {Name: "Formatted file", Path: "testdata/format/formatted.pkr.hcl"}, - {Name: "Directory", Path: "testdata/format", FormatExpected: true}, + {Name: "Unformatted file", Paths: []string{"testdata/format/unformatted.pkr.hcl"}, FormatExpected: true}, + {Name: "Unformatted vars file", Paths: []string{"testdata/format/unformatted.pkrvars.hcl"}, FormatExpected: true}, + {Name: "Formatted file", Paths: []string{"testdata/format/formatted.pkr.hcl"}}, + {Name: "Directory", Paths: []string{"testdata/format"}, FormatExpected: true}, } for _, tc := range tt { @@ -30,12 +30,12 @@ func TestHCL2Formatter_Format(t *testing.T) { var buf bytes.Buffer f := NewHCL2Formatter() f.Output = &buf - _, diags := f.Format(tc.Path) + _, diags := f.Format(tc.Paths) if diags.HasErrors() { t.Fatalf("the call to Format failed unexpectedly %s", diags.Error()) } if buf.String() != "" && tc.FormatExpected == false { - t.Errorf("Format(%q) should contain the name of the formatted file(s), but got %q", tc.Path, buf.String()) + t.Errorf("Format(%q) should contain the name of the formatted file(s), but got %q", tc.Paths, buf.String()) } } } @@ -61,7 +61,9 @@ func TestHCL2Formatter_Format_Write(t *testing.T) { _, _ = tf.Write(unformattedData) tf.Close() - _, diags := f.Format(tf.Name()) + var paths []string + paths = append(paths, tf.Name()) + _, diags := f.Format(paths) if diags.HasErrors() { t.Fatalf("the call to Format failed unexpectedly %s", diags.Error()) } @@ -94,7 +96,9 @@ func TestHCL2Formatter_Format_ShowDiff(t *testing.T) { ShowDiff: true, } - _, diags := f.Format("testdata/format/unformatted.pkr.hcl") + var paths []string + paths = append(paths, "testdata/format/unformatted.pkr.hcl") + _, diags := f.Format(paths) if diags.HasErrors() { t.Fatalf("the call to Format failed unexpectedly %s", diags.Error()) }