Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
backend "shipping-container" {}
}
33 changes: 29 additions & 4 deletions internal/command/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been looking into this, but I've added these TODO comments here so that it's clear these tests are defining current behaviour and not necessarily correct behaviour.

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(),
)
}
})
}
Expand Down