Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert: Fix MismatchMessage for object attributes #78

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
4 changes: 4 additions & 0 deletions cty/convert/mismatch_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func mismatchMessageObjects(got, want cty.Type) string {
continue
}

if gotAty.Equals(wantAty) {
continue // exact match, so no problem
}

// We'll now try to convert these attributes in isolation and
// see if we have a nested conversion error to report.
// We'll try an unsafe conversion first, and then fall back on
Expand Down
18 changes: 18 additions & 0 deletions cty/convert/mismatch_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ func TestMismatchMessage(t *testing.T) {
cty.List(cty.DynamicPseudoType),
`all list elements must have the same type`,
},
{
cty.Object(map[string]cty.Type{
"foo": cty.Bool,
"bar": cty.String,
"baz": cty.Object(map[string]cty.Type{
"boop": cty.Number,
}),
}),
cty.Object(map[string]cty.Type{
"foo": cty.Bool,
"bar": cty.String,
"baz": cty.Object(map[string]cty.Type{
"boop": cty.Number,
"beep": cty.Bool,
}),
}),
`attribute "baz": attribute "beep" is required`,
},
}

for _, test := range tests {
Expand Down