Skip to content

Commit a2e9e3c

Browse files
committed
add test case distinguishing legacy and new validate func
1 parent 9b30743 commit a2e9e3c

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

helper/schema/provider_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestProviderValidate_attributePath(t *testing.T) {
296296
Config map[string]interface{}
297297
ExpectedDiags diag.Diagnostics
298298
}{
299-
{ // validate path automatically built across list
299+
{ // legacy validate path automatically built, even across list
300300
P: &Provider{
301301
Schema: map[string]*Schema{
302302
"foo": {
@@ -334,6 +334,40 @@ func TestProviderValidate_attributePath(t *testing.T) {
334334
},
335335
},
336336
},
337+
{ // validate path automatically built, even across list
338+
P: &Provider{
339+
Schema: map[string]*Schema{
340+
"foo": {
341+
Type: TypeList,
342+
Required: true,
343+
Elem: &Resource{
344+
Schema: map[string]*Schema{
345+
"bar": {
346+
Type: TypeString,
347+
Required: true,
348+
ValidateDiagFunc: func(v interface{}, path cty.Path) diag.Diagnostics {
349+
return diag.Diagnostics{{Severity: diag.Error}}
350+
},
351+
},
352+
},
353+
},
354+
},
355+
},
356+
},
357+
Config: map[string]interface{}{
358+
"foo": []interface{}{
359+
map[string]interface{}{
360+
"bar": "baz",
361+
},
362+
},
363+
},
364+
ExpectedDiags: diag.Diagnostics{
365+
{
366+
Severity: diag.Error,
367+
AttributePath: cty.Path{cty.GetAttrStep{Name: "foo"}, cty.IndexStep{Key: cty.NumberIntVal(0)}, cty.GetAttrStep{Name: "bar"}},
368+
},
369+
},
370+
},
337371
{ // path is truncated at typeset
338372
P: &Provider{
339373
Schema: map[string]*Schema{

0 commit comments

Comments
 (0)