@@ -59,7 +59,7 @@ func (p *Parser) dirFileSet(dir string, opts ...Option) (ConfigFileSet, hcl.Diag
59
59
60
60
// Set up options
61
61
options := & Options {
62
- // We always process module and override files
62
+ // We always match module and override files
63
63
matchers : []FileMatcher {& moduleFiles {}},
64
64
testDirectory : DefaultTestDirectory ,
65
65
fs : p .fs ,
@@ -123,37 +123,31 @@ func (p *Parser) rootFiles(dir string, matchers []FileMatcher, fileSet *ConfigFi
123
123
case * queryFiles :
124
124
fileSet .Queries = append (fileSet .Queries , fullPath )
125
125
}
126
+ break // Stop checking other matchers once a match is found
126
127
}
127
128
}
128
129
}
129
130
130
131
return diags
131
132
}
132
133
133
- // WithFileHandler adds a file matcher to the parser
134
- func WithFileHandler ( matcher FileMatcher ) Option {
134
+ // MatchTestFiles adds a matcher for Terraform test files (.tftest.hcl and .tftest.json)
135
+ func MatchTestFiles ( dir string ) Option {
135
136
return func (o * Options ) {
136
- o .matchers = append (o .matchers , matcher )
137
+ o .testDirectory = dir
138
+ o .matchers = append (o .matchers , & testFiles {})
137
139
}
138
140
}
139
141
140
- // WithTestFiles adds a matcher for Terraform test files (.tftest .hcl and .tftest.json )
141
- func WithTestFiles ( dir string ) Option {
142
+ // MatchQueryFiles adds a matcher for Terraform query files (.tfquery .hcl)
143
+ func MatchQueryFiles ( ) Option {
142
144
return func (o * Options ) {
143
- o .testDirectory = dir
144
- WithFileHandler (& testFiles {})(o )
145
+ o .matchers = append (o .matchers , & queryFiles {})
145
146
}
146
147
}
147
148
148
- // WithQueryFiles adds a matcher for Terraform query files (.tfquery.hcl)
149
- func WithQueryFiles () Option {
150
- return WithFileHandler (& queryFiles {})
151
- }
152
-
153
- // moduleFiles processes regular Terraform configuration files (.tf and .tf.json)
154
- type moduleFiles struct {
155
- overrideOnly bool
156
- }
149
+ // moduleFiles matches regular Terraform configuration files (.tf and .tf.json)
150
+ type moduleFiles struct {}
157
151
158
152
func (m * moduleFiles ) Matches (name string ) bool {
159
153
ext := fileExt (name )
@@ -179,7 +173,7 @@ func (m *moduleFiles) DirFiles(dir string, options *Options, fileSet *ConfigFile
179
173
return nil
180
174
}
181
175
182
- // testFiles processes Terraform test files (.tftest.hcl and .tftest.json)
176
+ // testFiles matches Terraform test files (.tftest.hcl and .tftest.json)
183
177
type testFiles struct {}
184
178
185
179
func (t * testFiles ) Matches (name string ) bool {
@@ -189,7 +183,6 @@ func (t *testFiles) Matches(name string) bool {
189
183
func (t * testFiles ) DirFiles (dir string , opts * Options , fileSet * ConfigFileSet ) hcl.Diagnostics {
190
184
var diags hcl.Diagnostics
191
185
192
- // Process test directory
193
186
testPath := path .Join (dir , opts .testDirectory )
194
187
testInfos , err := opts .fs .ReadDir (testPath )
195
188
@@ -228,14 +221,19 @@ func (t *testFiles) DirFiles(dir string, opts *Options, fileSet *ConfigFileSet)
228
221
229
222
// Process test directory files
230
223
for _ , info := range testInfos {
224
+ if info .IsDir () || IsIgnoredFile (info .Name ()) {
225
+ // We only care about files.
226
+ continue
227
+ }
228
+
231
229
name := info .Name ()
232
230
fileSet .Tests = append (fileSet .Tests , filepath .Join (testPath , name ))
233
231
}
234
232
235
233
return diags
236
234
}
237
235
238
- // queryFiles processes Terraform query files (.tfquery.hcl)
236
+ // queryFiles matches Terraform query files (.tfquery.hcl)
239
237
type queryFiles struct {}
240
238
241
239
func (q * queryFiles ) Matches (name string ) bool {
0 commit comments