mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Adds checks for not getting validation errors when they are expected
This commit is contained in:
parent
95eb523c02
commit
2d12f242c7
@ -217,6 +217,16 @@ func (b *Backend) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics)
|
|||||||
return obj, diags
|
return obj, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val := obj.GetAttr("bucket"); val.IsNull() || val.AsString() == "" {
|
||||||
|
diags = diags.Append(tfdiags.AttributeValue(
|
||||||
|
tfdiags.Error,
|
||||||
|
"Invalid bucket value",
|
||||||
|
// `The "bucket" attribute value must not be empty.`,
|
||||||
|
`"bucket": required field is not set`,
|
||||||
|
cty.Path{cty.GetAttrStep{Name: "bucket"}},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
if val := obj.GetAttr("key"); val.IsNull() || val.AsString() == "" {
|
if val := obj.GetAttr("key"); val.IsNull() || val.AsString() == "" {
|
||||||
diags = diags.Append(tfdiags.AttributeValue(
|
diags = diags.Append(tfdiags.AttributeValue(
|
||||||
tfdiags.Error,
|
tfdiags.Error,
|
||||||
@ -237,7 +247,7 @@ func (b *Backend) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics)
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := obj.GetAttr("region"); val.IsNull() {
|
if val := obj.GetAttr("region"); val.IsNull() || val.AsString() == "" {
|
||||||
if os.Getenv("AWS_REGION") == "" && os.Getenv("AWS_DEFAULT_REGION") == "" {
|
if os.Getenv("AWS_REGION") == "" && os.Getenv("AWS_DEFAULT_REGION") == "" {
|
||||||
diags = diags.Append(tfdiags.AttributeValue(
|
diags = diags.Append(tfdiags.AttributeValue(
|
||||||
tfdiags.Error,
|
tfdiags.Error,
|
||||||
|
@ -614,11 +614,17 @@ func TestBackendConfig_PrepareConfigValidation(t *testing.T) {
|
|||||||
b := New()
|
b := New()
|
||||||
|
|
||||||
_, valDiags := b.PrepareConfig(populateSchema(t, b.ConfigSchema(), tc.config))
|
_, valDiags := b.PrepareConfig(populateSchema(t, b.ConfigSchema(), tc.config))
|
||||||
if valDiags.Err() != nil && tc.expectedErr != "" {
|
if tc.expectedErr != "" {
|
||||||
actualErr := valDiags.Err().Error()
|
if valDiags.Err() != nil {
|
||||||
if !strings.Contains(actualErr, tc.expectedErr) {
|
actualErr := valDiags.Err().Error()
|
||||||
t.Fatalf("unexpected validation result: %v", valDiags.Err())
|
if !strings.Contains(actualErr, tc.expectedErr) {
|
||||||
|
t.Fatalf("unexpected validation result: %v", valDiags.Err())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Fatal("expected an error, got none")
|
||||||
}
|
}
|
||||||
|
} else if valDiags.Err() != nil {
|
||||||
|
t.Fatalf("expected no error, got %s", valDiags.Err())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -666,11 +672,17 @@ func TestBackendConfig_PrepareConfigWithEnvVars(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
_, valDiags := b.PrepareConfig(populateSchema(t, b.ConfigSchema(), tc.config))
|
_, valDiags := b.PrepareConfig(populateSchema(t, b.ConfigSchema(), tc.config))
|
||||||
if valDiags.Err() != nil && tc.expectedErr != "" {
|
if tc.expectedErr != "" {
|
||||||
actualErr := valDiags.Err().Error()
|
if valDiags.Err() != nil {
|
||||||
if !strings.Contains(actualErr, tc.expectedErr) {
|
actualErr := valDiags.Err().Error()
|
||||||
t.Fatalf("unexpected validation result: %v", valDiags.Err())
|
if !strings.Contains(actualErr, tc.expectedErr) {
|
||||||
|
t.Fatalf("unexpected validation result: %v", valDiags.Err())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.Fatal("expected an error, got none")
|
||||||
}
|
}
|
||||||
|
} else if valDiags.Err() != nil {
|
||||||
|
t.Fatalf("expected no error, got %s", valDiags.Err())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user