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

Cross test program generation failures. #2022

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
188 changes: 188 additions & 0 deletions pkg/tests/cross-tests/input_cross_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,191 @@ func TestEmptySetOfEmptyObjects(t *testing.T) {
Config: config,
})
}

func TestRequiredEmptyListOfObjects(t *testing.T) {
skipUnlessLinux(t)
t.Skipf("TODO[pulumi/pulumi-terraform-bridge#2021]: Make sure we also error on the pulumi side!")
// │ Error: Insufficient d3f0 blocks
// │
// │ on test.tf line 1, in resource "crossprovider_testres" "example":
// │ 1: resource "crossprovider_testres" "example" {
// │
// │ At least 1 "d3f0" blocks are required.

t1 := tftypes.Object{}
t0 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"d3f0": tftypes.List{ElementType: t1},
}}
config := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.List{ElementType: t1}, []tftypes.Value{}),
})

runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{}},
MaxItems: 1,
},
},
},
Config: config,
})
}

func TestRequiredListOfEmptyObjects(t *testing.T) {
skipUnlessLinux(t)

t1 := tftypes.Map{ElementType: tftypes.String}
emptyObj := tftypes.NewValue(t1, map[string]tftypes.Value{})
t0 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"d3f0": tftypes.List{ElementType: t1},
}}

listOfEmptyObj := tftypes.NewValue(
tftypes.List{ElementType: t1}, []tftypes.Value{emptyObj},
)
config := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": listOfEmptyObj,
})

runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
MaxItems: 1,
},
},
},
Config: config,
ObjectType: &t0,
})
}

func TestRequiredEmptyListOfLists(t *testing.T) {
skipUnlessLinux(t)
// Error: crossprovider:index:TestRes is not assignable from {}
// Cannot assign '{}' to 'crossprovider:index:TestRes':
// d3f0: Missing required property 'd3f0'

t1 := tftypes.List{ElementType: tftypes.String}
t0 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"d3f0": tftypes.List{ElementType: t1},
}}
config := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.List{ElementType: t1}, []tftypes.Value{}),
})

runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeString},
},
MaxItems: 1,
},
},
},
Config: config,
})
}

func TestRequiredEmptyListOfSets(t *testing.T) {
skipUnlessLinux(t)
// Error: crossprovider:index:TestRes is not assignable from {}
// Cannot assign '{}' to 'crossprovider:index:TestRes':
// d3f0: Missing required property 'd3f0'

t1 := tftypes.Set{ElementType: tftypes.String}
t0 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"d3f0": tftypes.List{ElementType: t1},
}}
config := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.List{ElementType: t1}, []tftypes.Value{}),
})

runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString},
},
MaxItems: 1,
},
},
},
Config: config,
})
}

func TestNonEmptyNestedMaxItemsOnes(t *testing.T) {
skipUnlessLinux(t)
// Error: crossprovider:index:TestRes is not assignable from {}
// Cannot assign '{}' to 'crossprovider:index:TestRes':
// d3f0: Missing required property 'd3f0'

t1 := tftypes.List{ElementType: tftypes.String}
t0 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"d3f0": tftypes.List{ElementType: t1},
}}
// Non-empty
config1 := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.List{ElementType: t1}, []tftypes.Value{
tftypes.NewValue(t1, []tftypes.Value{
tftypes.NewValue(tftypes.String, "foo"),
}),
}),
})
// first level empty
config2 := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.List{ElementType: t1}, []tftypes.Value{}),
})
// second level empty - this is impossible to handle because of flattening
_ = tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.List{ElementType: t1}, []tftypes.Value{
tftypes.NewValue(t1, []tftypes.Value{}),
}),
})

for _, tc := range []struct {
name string
config tftypes.Value
}{
{"non-empty", config1},
{"first-level-empty", config2},
// {"second-level-empty", config3},
} {
t.Run(tc.name, func(t *testing.T) {
runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
MaxItems: 1,
},
},
},
Config: tc.config,
})
})
}
}
38 changes: 38 additions & 0 deletions pkg/tests/cross-tests/tfwrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,44 @@ resource "res" "ex" {
resource "res" "ex" {
f0 = null
}
`),
},
{
"empty-block-of-objects",
cty.ObjectVal(map[string]cty.Value{"f0": cty.ListValEmpty(cty.EmptyObject)}),
map[string]*schema.Schema{
"f0": {
Required: true,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
MaxItems: 1,
},
},
autogold.Expect(`
resource "res" "ex" {
}
`),
},
{
"block-of-empty-object",
cty.ObjectVal(map[string]cty.Value{"f0": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{})})}),
map[string]*schema.Schema{
"f0": {
Required: true,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
MaxItems: 1,
},
},
autogold.Expect(`
resource "res" "ex" {
f0 {
}
}
`),
},
}
Expand Down
Loading