test: Show warning when a `-filter` flag has an invalid value (#38603)

* test: Show warning when a test file filter is not valid

* Add change file
main
Sarah French 3 days ago committed by GitHub
parent f6553bae93
commit d174972029
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'test: Terraform will now raise a warning when a file referenced via `-filter` flag does not exist.'
time: 2026-05-15T20:13:07.430709+01:00
custom:
Issue: "38603"

@ -180,7 +180,7 @@ func (runner *TestSuiteRunner) collectTests() (*moduletest.Suite, tfdiags.Diagno
// If the filter is invalid, we'll simply skip this
// entry and print a warning. But we could still execute
// any other tests within the filter.
diags.Append(tfdiags.Sourceless(
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Warning,
"Unknown test file",
fmt.Sprintf("The specified test file, %s, could not be found.", name)))

@ -179,6 +179,15 @@ func TestTest_Runs(t *testing.T) {
expectedOut: []string{"1 passed, 0 failed"},
code: 0,
},
"multiple_files_with_invalid_filter": {
override: "multiple_files",
args: []string{"-filter=nonexistent.tftest.hcl"},
expectedOut: []string{
"Success! 0 passed, 0 failed.",
"Warning: Unknown test file",
},
code: 0,
},
"no_state": {
expectedOut: []string{"0 passed, 1 failed"},
expectedErr: []string{"No value for required variable"},

Loading…
Cancel
Save