Skip to content

Commit

Permalink
Add a test for a single-nested-block
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Nov 1, 2024
1 parent 4ba9f31 commit 9bcae10
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/internal/tests/cross-tests/tfwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func writePfBlock(key string, parentBody *hclwrite.Body, schemas pfproviderschem
case pfproviderschema.SingleNestedBlock:
body := parentBody.AppendNewBlock(key, nil).Body()

if value.IsNull() {
return
}

writePfObject(body, pfproviderschema.NestedBlockObject{
Attributes: schemas.Attributes,
Blocks: schemas.Blocks,
Expand Down
87 changes: 84 additions & 3 deletions pkg/pf/tests/provider_configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,55 @@ func TestConfigure(t *testing.T) {
},
))
})

t.Run("single-nested-block", func(t *testing.T) {
t.Parallel()

optionalAttrs := schema.Schema{Blocks: map[string]schema.Block{
"o": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"n1": schema.StringAttribute{Optional: true},
"n2": schema.BoolAttribute{Optional: true},
},
},
}}

t.Run("missing", crosstests.MakeConfigure(optionalAttrs,
map[string]cty.Value{},
))

t.Run("empty", crosstests.MakeConfigure(optionalAttrs,
map[string]cty.Value{"o": cty.EmptyObjectVal},
))

t.Run("null", func(t *testing.T) {
t.Skip("TODO[pulumi/pulumi-terraform-bridge#2564] Null blocks don't match")
t.Parallel()
crosstests.Configure(t,
optionalAttrs,
map[string]cty.Value{
"o": cty.NullVal(cty.Object(map[string]cty.Type{"n1": cty.String, "n2": cty.Bool})),
},
)
})

t.Run("full", crosstests.MakeConfigure(optionalAttrs,
map[string]cty.Value{
"o": cty.ObjectVal(map[string]cty.Value{
"n1": cty.StringVal("123"),
"n2": cty.BoolVal(false),
}),
},
))

t.Run("partial", crosstests.MakeConfigure(optionalAttrs,
map[string]cty.Value{
"o": cty.ObjectVal(map[string]cty.Value{
"n1": cty.StringVal("123"),
}),
},
))
})
}

func TestConfigureNameOverrides(t *testing.T) {
Expand All @@ -182,9 +231,9 @@ func TestConfigureNameOverrides(t *testing.T) {
}),
))

t.Run("nested-attribute", func(t *testing.T) {
t.Run("single-nested-attribute", func(t *testing.T) {
t.Skip("TODO[pulumi/pulumi-terraform-bridge#2560]: SingleNestedAttribute nested type overrides don't line up for PF")
t.Parallel()
t.Skip("TODO[pulumi/pulumi-terraform-bridge#2560]: Attribute nested type overrides don't line up for PF")
crosstests.Configure(t,
schema.Schema{
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -212,7 +261,36 @@ func TestConfigureNameOverrides(t *testing.T) {
)
})

t.Run("nested-block", crosstests.MakeConfigure(
t.Run("single-nested-block", func(t *testing.T) {
t.Skip("TODO[pulumi/pulumi-terraform-bridge#2560]: SingleNestedBlock type overrides don't line up for PF")
t.Parallel()
crosstests.Configure(t,
schema.Schema{
Blocks: map[string]schema.Block{
"a": schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"as": schema.Int64Attribute{Optional: true},
},
},
},
},
map[string]cty.Value{
"a": cty.ObjectVal(map[string]cty.Value{
"as": cty.NumberIntVal(123),
}),
},
crosstests.ConfigureProviderInfo(map[string]*info.Schema{
"a": {
Name: "puAttr",
Elem: &info.Schema{Fields: map[string]*info.Schema{
"as": {Name: "puNestedAttrField"},
}},
},
}),
)
})

t.Run("list-nested-block", crosstests.MakeConfigure(
schema.Schema{
Blocks: map[string]schema.Block{
"b": schema.ListNestedBlock{NestedObject: schema.NestedBlockObject{
Expand Down Expand Up @@ -261,6 +339,7 @@ type testConfigureCollection struct {

func (tc testConfigureCollection) run(t *testing.T) {
t.Parallel()
t.Helper()

t.Run("missing", crosstests.MakeConfigure(
schema.Schema{Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -309,6 +388,8 @@ type testConfigurePrimitive struct {

func (tc testConfigurePrimitive) run(t *testing.T) {
t.Parallel()
t.Helper()

t.Run("zero value - optional", crosstests.MakeConfigure(
schema.Schema{Attributes: map[string]schema.Attribute{
"v": tc.attrOptional,
Expand Down

0 comments on commit 9bcae10

Please sign in to comment.