Skip to content
Merged
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
61 changes: 61 additions & 0 deletions ext/typeexpr/get_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,67 @@ func TestGetTypeDefaults(t *testing.T) {
"",
},

// Lists should remove optional metadata from the concrete default
// values.
{
`object({ list = optional(list(object({ required = string, optional = optional(string) })), [])})`,
&Defaults{
Type: cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"list": cty.List(cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"required": cty.String,
"optional": cty.String,
}, []string{"optional"})),
}, []string{"list"}),
DefaultValues: map[string]cty.Value{
"list": cty.ListValEmpty(cty.Object(map[string]cty.Type{
"required": cty.String,
"optional": cty.String,
})),
},
},
``,
},

// Lists should remove optional metadata from the concrete default
// values but should still apply recursive defaults.
{
`object({ list = optional(list(object({ required = string, optional = optional(string, "optional") })), [{ required = "required" }])})`,
&Defaults{
Type: cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"list": cty.List(cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"required": cty.String,
"optional": cty.String,
}, []string{"optional"})),
}, []string{"list"}),
DefaultValues: map[string]cty.Value{
"list": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{
"required": cty.StringVal("required"),
"optional": cty.NullVal(cty.String),
})}),
},
Children: map[string]*Defaults{
"list": {
Type: cty.List(cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"required": cty.String,
"optional": cty.String,
}, []string{"optional"})),
Children: map[string]*Defaults{
"": {
Type: cty.ObjectWithOptionalAttrs(map[string]cty.Type{
"required": cty.String,
"optional": cty.String,
}, []string{"optional"}),
DefaultValues: map[string]cty.Value{
"optional": cty.StringVal("optional"),
},
},
},
},
},
},
``,
},

// incompatible default value causes an error
{
`object({ a = optional(string, "hello"), b = optional(number, true) })`,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7
github.com/sergi/go-diff v1.0.0
github.com/spf13/pflag v1.0.2
github.com/zclconf/go-cty v1.12.0
github.com/zclconf/go-cty v1.12.1
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6Ac
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.12.0 h1:F5E/vbilcrCtat9sYcEjlwwg1mDqbRTjyXR57nnx5sc=
github.com/zclconf/go-cty v1.12.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY=
github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0=
Expand Down