Skip to content

Commit 40db0a7

Browse files
committed
It passes (at least once)
1 parent 0d9aec0 commit 40db0a7

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

pf/tests/provider_configure_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ func TestConfigureProperties(t *testing.T) {
102102
asMapOrObject := map[string]tftypes.Value{}
103103
require.NoError(t, v.As(&asMapOrObject))
104104

105+
for k, e := range asMapOrObject {
106+
e = patchUp(e)
107+
if e.IsNull() && typ.Is(tftypes.Map{}) {
108+
delete(asMapOrObject, k)
109+
} else {
110+
asMapOrObject[k] = e
111+
}
112+
}
113+
105114
// TODO: Empty objects are represented as {} in PF but null in bridged PF.
106115
//
107116
// This normalizes all empty objects to be represented as null so the test passes.
@@ -110,9 +119,6 @@ func TestConfigureProperties(t *testing.T) {
110119
return tftypes.NewValue(v.Type(), nil)
111120
}
112121

113-
for k, e := range asMapOrObject {
114-
asMapOrObject[k] = patchUp(e)
115-
}
116122
return tftypes.NewValue(v.Type(), asMapOrObject)
117123
}
118124

pf/tests/util/property/pf/value/provider/util.go

+18-11
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,21 @@ func convertSet(a []value, elem cty.Type) value {
207207
puArr[i] = v.pu
208208
}
209209

210-
set := cty.SetValEmpty(elem)
210+
tfSet := cty.NullVal(cty.Set(elem))
211211
if len(tfArr) > 0 {
212-
set = cty.SetVal(tfArr)
212+
tfSet = cty.SetVal(tfArr)
213+
contract.Assertf(tfSet.LengthInt() == len(puArr),
214+
"Set values have different lengths: (%d != %d), of %#v", tfSet.LengthInt(), len(puArr), a)
215+
}
216+
puSet := resource.NewNullProperty()
217+
if len(puArr) > 0 {
218+
puSet = resource.NewProperty(puArr)
213219
}
214-
215-
contract.Assertf(set.LengthInt() == len(puArr),
216-
"Set values have different lengths: (%d != %d), of %#v", set.LengthInt(), len(puArr), a)
217220

218221
return value{
219222
hasValue: true,
220-
tf: set,
221-
pu: resource.NewProperty(puArr),
223+
tf: tfSet,
224+
pu: puSet,
222225
}
223226
}
224227

@@ -233,15 +236,19 @@ func convertList(a []value, elem cty.Type) value {
233236
puArr[i] = v.pu
234237
}
235238

236-
ctyList := cty.ListValEmpty(elem)
239+
tfList := cty.NullVal(cty.List(elem))
237240
if len(tfArr) > 0 {
238-
ctyList = cty.ListVal(tfArr)
241+
tfList = cty.ListVal(tfArr)
242+
}
243+
puList := resource.NewNullProperty()
244+
if len(puArr) > 0 {
245+
puList = resource.NewProperty(puArr)
239246
}
240247

241248
return value{
242249
hasValue: true,
243-
tf: ctyList,
244-
pu: resource.NewProperty(puArr),
250+
tf: tfList,
251+
pu: puList,
245252
}
246253
}
247254

pf/tests/util/property/pf/value/provider/value.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (g generator) withAttr(ctx context.Context, attribute schema.Attribute) *ra
100100
})
101101
}
102102

103+
var minIterableSize int
104+
if attribute.IsRequired() {
105+
minIterableSize = 1
106+
}
107+
103108
getValue := func() *rapid.Generator[value] {
104109
switch attribute := attribute.(type) {
105110

@@ -125,20 +130,23 @@ func (g generator) withAttr(ctx context.Context, attribute schema.Attribute) *ra
125130
case schema.MapAttribute:
126131
elemType := attribute.ElementType
127132
return rapid.Map(
128-
rapid.MapOf(stringV(), g.attrType(ctx, elemType)),
133+
rapid.MapOfN(
134+
stringV(), g.attrType(ctx, elemType),
135+
minIterableSize, maxIterableSize,
136+
),
129137
makeConvertMap(ctyType(elemType.TerraformType(ctx))),
130138
)
131139

132140
case schema.ListAttribute:
133141
elemType := attribute.ElementType
134142
return rapid.Map(
135-
rapid.SliceOfN(g.attrType(ctx, elemType), 0, maxIterableSize),
143+
rapid.SliceOfN(g.attrType(ctx, elemType), minIterableSize, maxIterableSize),
136144
makeConvertList(ctyType(elemType.TerraformType(ctx))),
137145
)
138146
case schema.SetAttribute:
139147
elemType := attribute.ElementType
140148
return rapid.Map(
141-
rapid.SliceOfNDistinct(g.attrType(ctx, elemType), 0, maxIterableSize, g.valueID),
149+
rapid.SliceOfNDistinct(g.attrType(ctx, elemType), minIterableSize, maxIterableSize, g.valueID),
142150
makeConvertSet(ctyType(elemType.TerraformType(ctx))),
143151
)
144152

@@ -165,17 +173,17 @@ func (g generator) withAttr(ctx context.Context, attribute schema.Attribute) *ra
165173
})
166174
case schema.MapNestedAttribute:
167175
return rapid.Map(
168-
rapid.MapOfN(stringV(), g.nestedAttributeObject(ctx, attribute.NestedObject), 0, maxIterableSize),
176+
rapid.MapOfN(stringV(), g.nestedAttributeObject(ctx, attribute.NestedObject), minIterableSize, maxIterableSize),
169177
makeConvertMap(ctyType(attribute.NestedObject.Type().TerraformType(ctx))),
170178
)
171179
case schema.ListNestedAttribute:
172180
return rapid.Map(
173-
rapid.SliceOfN(g.nestedAttributeObject(ctx, attribute.NestedObject), 0, maxIterableSize),
181+
rapid.SliceOfN(g.nestedAttributeObject(ctx, attribute.NestedObject), minIterableSize, maxIterableSize),
174182
makeConvertList(ctyType(attribute.NestedObject.Type().TerraformType(ctx))),
175183
)
176184
case schema.SetNestedAttribute:
177185
return rapid.Map(
178-
rapid.SliceOfNDistinct(g.nestedAttributeObject(ctx, attribute.NestedObject), 0, maxIterableSize, g.valueID),
186+
rapid.SliceOfNDistinct(g.nestedAttributeObject(ctx, attribute.NestedObject), minIterableSize, maxIterableSize, g.valueID),
179187
makeConvertSet(ctyType(attribute.NestedObject.Type().TerraformType(ctx))),
180188
)
181189
default:

pkg/tests/cross-tests/tfwrite.go

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func writePfProvider(body *hclwrite.Body, schemas pfproviderschema.Schema, value
8282
// This is why writePfBlock is called with parentBody, instead of with the block body
8383
// already created (as with [writeBlock]).
8484
func writePfBlock(key string, parentBody *hclwrite.Body, schemas pfproviderschema.Block, value cty.Value) {
85+
if value.IsNull() {
86+
return
87+
}
8588
switch schemas := schemas.(type) {
8689
case pfproviderschema.ListNestedBlock:
8790
for _, v := range value.AsValueSlice() {

0 commit comments

Comments
 (0)