Skip to content

Commit

Permalink
test: block attributes with MarkComputedNilsAsUnknown (#555)
Browse files Browse the repository at this point in the history
additional test coverage for the MarkComputedNilsAsUnknown changes
added in #552
  • Loading branch information
jar-b committed Nov 28, 2022
1 parent 6d0a863 commit 1dfcd30
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions internal/fwserver/server_planresourcechange_test.go
Expand Up @@ -115,6 +115,41 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) {
Computed: true,
},
},
Blocks: map[string]tfsdk.Block{
// nil blocks should remain nil
"block-nil-optional-computed": {
Attributes: map[string]tfsdk.Attribute{
"string-nil": {
Type: types.StringType,
Optional: true,
Computed: true,
},
"string-set": {
Type: types.StringType,
Optional: true,
Computed: true,
},
},
NestingMode: tfsdk.BlockNestingModeSet,
},
"block-value-optional-computed": {
Attributes: map[string]tfsdk.Attribute{
// nested computed attributes should be unknown
"string-nil": {
Type: types.StringType,
Optional: true,
Computed: true,
},
// nested non-nil computed attributes should be left alone
"string-set": {
Type: types.StringType,
Optional: true,
Computed: true,
},
},
NestingMode: tfsdk.BlockNestingModeSet,
},
},
}
input := tftypes.NewValue(s.Type().TerraformType(context.Background()), map[string]tftypes.Value{
"string-value": tftypes.NewValue(tftypes.String, "hello, world"),
Expand Down Expand Up @@ -152,6 +187,32 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) {
"string-nil": tftypes.NewValue(tftypes.String, nil),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
"block-nil-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, nil),
"block-value-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, []tftypes.Value{
tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
}, map[string]tftypes.Value{
"string-nil": tftypes.NewValue(tftypes.String, nil),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
}),
})
expected := tftypes.NewValue(s.Type().TerraformType(context.Background()), map[string]tftypes.Value{
"string-value": tftypes.NewValue(tftypes.String, "hello, world"),
Expand Down Expand Up @@ -189,6 +250,32 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) {
"string-nil": tftypes.NewValue(tftypes.String, tftypes.UnknownValue),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
"block-nil-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, nil),
"block-value-optional-computed": tftypes.NewValue(tftypes.Set{
ElementType: tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
},
}, []tftypes.Value{
tftypes.NewValue(tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"string-nil": tftypes.String,
"string-set": tftypes.String,
},
}, map[string]tftypes.Value{
"string-nil": tftypes.NewValue(tftypes.String, tftypes.UnknownValue),
"string-set": tftypes.NewValue(tftypes.String, "bar"),
}),
}),
})

got, err := tftypes.Transform(input, fwserver.MarkComputedNilsAsUnknown(context.Background(), input, s))
Expand Down

0 comments on commit 1dfcd30

Please sign in to comment.