Skip to content

Commit baa894f

Browse files
integraration tests
1 parent a2b4bf5 commit baa894f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

pkg/tests/schema_pulumi_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,3 +1410,81 @@ Resources:
14101410
})
14111411
}
14121412
}
1413+
1414+
func TestFullyComputedNestedAttribute(t *testing.T) {
1415+
resMap := map[string]*schema.Resource{
1416+
"prov_test": {
1417+
Schema: map[string]*schema.Schema{
1418+
"attached_disks": {
1419+
Type: schema.TypeList,
1420+
Optional: true,
1421+
Elem: &schema.Resource{
1422+
Schema: map[string]*schema.Schema{
1423+
"name": {
1424+
Optional: true,
1425+
Type: schema.TypeString,
1426+
},
1427+
"key256": {
1428+
Computed: true,
1429+
Type: schema.TypeString,
1430+
},
1431+
},
1432+
},
1433+
},
1434+
"top_level_computed": {
1435+
Type: schema.TypeString,
1436+
Computed: true,
1437+
},
1438+
},
1439+
},
1440+
}
1441+
1442+
importer := func(val any) func(context.Context, *schema.ResourceData, interface{}) ([]*schema.ResourceData, error) {
1443+
return func(ctx context.Context, rd *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
1444+
elMap := map[string]any{
1445+
"name": "disk1",
1446+
"key256": val,
1447+
}
1448+
err := rd.Set("attached_disks", []map[string]any{elMap})
1449+
require.NoError(t, err)
1450+
1451+
err = rd.Set("top_level_computed", "computed_val")
1452+
require.NoError(t, err)
1453+
1454+
return []*schema.ResourceData{rd}, nil
1455+
}
1456+
}
1457+
bridgedProvider := pulcheck.BridgedProvider(t, "prov", resMap)
1458+
1459+
program := `
1460+
name: test
1461+
runtime: yaml
1462+
`
1463+
for _, tc := range []struct {
1464+
name string
1465+
importVal any
1466+
}{
1467+
{
1468+
"non-nil",
1469+
"val1",
1470+
},
1471+
{
1472+
"nil",
1473+
nil,
1474+
},
1475+
} {
1476+
t.Run(tc.name, func(t *testing.T) {
1477+
resMap["prov_test"].Importer = &schema.ResourceImporter{
1478+
StateContext: importer(tc.importVal),
1479+
}
1480+
1481+
pt := pulcheck.PulCheck(t, bridgedProvider, program)
1482+
1483+
res := pt.Import("prov:index/test:Test", "res1", "id1", "")
1484+
1485+
t.Logf(res.Stdout)
1486+
1487+
require.NotContains(t, res.Stdout, "One or more imported inputs failed to validate")
1488+
})
1489+
}
1490+
}

0 commit comments

Comments
 (0)