test: Add more test coverage of `validate` command's interaction with `backend` blocks (#37977)

* test: Show how the validate command doesn't detect when an unknown backend type is in the config.

* test: Minor fixes to error messages when test fails

* test: Add some TODOs in code comments

These tests are here to define existing behaviour, not define desired behaviour. I wanted to make that clear!
pull/37959/head^2
Sarah French 5 months ago committed by GitHub
parent 33d54b9a7c
commit 940fbfb7ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
terraform {
backend "shipping-container" {}
}

@ -538,18 +538,43 @@ func TestValidate_backendBlocks(t *testing.T) {
if code != 1 {
t.Fatalf("unexpected successful exit code %d\n\n%s", code, output.Stdout())
}
if !strings.Contains(output.Stderr(), "Error: Attribute redefined") {
expectedErr := "Error: Attribute redefined"
if !strings.Contains(output.Stderr(), expectedErr) {
t.Fatalf("unexpected error content: wanted %q, got: %s",
"Error: Attribute redefined",
expectedErr,
output.Stderr(),
)
}
})
// TODO: Should this validation be added?
t.Run("NOT invalid when the backend type is unknown", func(t *testing.T) {
output, code := setupTest(t, "invalid-backend-configuration/unknown-backend-type")
if code != 0 {
t.Fatalf("expected a successful exit code %d\n\n%s", code, output.Stderr())
}
expectedMsg := "Success! The configuration is valid."
if !strings.Contains(output.Stdout(), expectedMsg) {
t.Fatalf("unexpected output content: wanted %q, got: %s",
expectedMsg,
output.Stdout(),
)
}
})
// Backend blocks aren't validated using their schemas currently.
// TODO: Should this validation be added?
t.Run("NOT invalid when there's an unknown attribute present", func(t *testing.T) {
if output, code := setupTest(t, "invalid-backend-configuration/unknown-attr"); code != 0 {
t.Fatalf("unexpected non-successful exit code %d\n\n%s", code, output.Stderr())
output, code := setupTest(t, "invalid-backend-configuration/unknown-attr")
if code != 0 {
t.Fatalf("expected a successful exit code %d\n\n%s", code, output.Stderr())
}
expectedMsg := "Success! The configuration is valid."
if !strings.Contains(output.Stdout(), expectedMsg) {
t.Fatalf("unexpected output content: wanted %q, got: %s",
expectedMsg,
output.Stdout(),
)
}
})
}

Loading…
Cancel
Save