File tree 1 file changed +29
-3
lines changed
1 file changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,16 @@ import (
6
6
"math/rand"
7
7
"os"
8
8
"path/filepath"
9
+ "slices"
9
10
"strconv"
10
11
"strings"
11
12
"sync"
12
13
"testing"
13
14
"text/template"
14
15
"time"
16
+
17
+ hcl "github.com/hashicorp/hcl/v2"
18
+ hclwrite "github.com/hashicorp/hcl/v2/hclwrite"
15
19
)
16
20
17
21
var rng * rand.Rand
@@ -133,9 +137,31 @@ func (ts *Manager) Render(t *testing.T, args ...interface{}) string {
133
137
buf .WriteString ("\n " )
134
138
}
135
139
136
- hcl := strings .TrimSpace (buf .String ())
137
- t .Logf ("\n \n HCL:\n %s\n " , addLineNumbers (hcl ))
138
- return hcl
140
+ definition := buf .String ()
141
+
142
+ {
143
+ // Remove empty lines
144
+ lines := strings .Split (definition , "\n " )
145
+ lines = slices .DeleteFunc (lines , func (line string ) bool { return strings .TrimSpace (line ) == "" })
146
+ definition = strings .Join (lines , "\n " )
147
+ }
148
+
149
+ {
150
+ // Format HCL files
151
+ buf := bytes .NewBuffer (nil )
152
+ file , diags := hclwrite .ParseConfig ([]byte (definition ), "testing.tf" , hcl .InitialPos )
153
+ if diags .HasErrors () {
154
+ t .Fatal (diags .Error ())
155
+ }
156
+ if _ , err := file .WriteTo (buf ); err != nil {
157
+ t .Fatal (err )
158
+ }
159
+ definition = buf .String ()
160
+ }
161
+
162
+ t .Logf ("\n \n HCL:\n %s\n " , addLineNumbers (definition ))
163
+
164
+ return definition
139
165
}
140
166
141
167
func parseTmplGlob (t * testing.T , root * template.Template , prefix , glob string ) {
You can’t perform that action at this time.
0 commit comments