mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
31349a9c3a
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package configs
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func TestSynthBodyContent(t *testing.T) {
|
|
tests := map[string]struct {
|
|
Values map[string]cty.Value
|
|
Schema *hcl.BodySchema
|
|
DiagCount int
|
|
}{
|
|
"empty": {
|
|
Values: map[string]cty.Value{},
|
|
Schema: &hcl.BodySchema{},
|
|
DiagCount: 0,
|
|
},
|
|
"missing required attribute": {
|
|
Values: map[string]cty.Value{},
|
|
Schema: &hcl.BodySchema{
|
|
Attributes: []hcl.AttributeSchema{
|
|
{
|
|
Name: "nonexist",
|
|
Required: true,
|
|
},
|
|
},
|
|
},
|
|
DiagCount: 1, // missing required attribute
|
|
},
|
|
"missing optional attribute": {
|
|
Values: map[string]cty.Value{},
|
|
Schema: &hcl.BodySchema{
|
|
Attributes: []hcl.AttributeSchema{
|
|
{
|
|
Name: "nonexist",
|
|
},
|
|
},
|
|
},
|
|
DiagCount: 0,
|
|
},
|
|
"extraneous attribute": {
|
|
Values: map[string]cty.Value{
|
|
"foo": cty.StringVal("unwanted"),
|
|
},
|
|
Schema: &hcl.BodySchema{},
|
|
DiagCount: 1, // unsupported attribute
|
|
},
|
|
}
|
|
|
|
for name, test := range tests {
|
|
t.Run(name, func(t *testing.T) {
|
|
body := SynthBody("synth", test.Values)
|
|
_, diags := body.Content(test.Schema)
|
|
if got, want := len(diags), test.DiagCount; got != want {
|
|
t.Errorf("wrong number of diagnostics %d; want %d", got, want)
|
|
for _, diag := range diags {
|
|
t.Logf("- %s", diag)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|