Skip to content

Commit 3e81b9c

Browse files
fix merge
1 parent e9d7ff7 commit 3e81b9c

File tree

1 file changed

+109
-77
lines changed

1 file changed

+109
-77
lines changed

pkg/pf/tests/diff_set_test.go

Lines changed: 109 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -21,119 +21,135 @@ import (
2121
func TestDetailedDiffSet(t *testing.T) {
2222
t.Parallel()
2323

24-
attributeSchema := rschema.Schema{
25-
Attributes: map[string]rschema.Attribute{
26-
"key": rschema.SetAttribute{
27-
Optional: true,
28-
ElementType: types.StringType,
24+
attributeSchema := pb.NewResource(pb.NewResourceArgs{
25+
ResourceSchema: rschema.Schema{
26+
Attributes: map[string]rschema.Attribute{
27+
"key": rschema.SetAttribute{
28+
Optional: true,
29+
ElementType: types.StringType,
30+
},
2931
},
3032
},
31-
}
33+
})
3234

33-
attributeReplaceSchema := rschema.Schema{
34-
Attributes: map[string]rschema.Attribute{
35-
"key": rschema.SetAttribute{
36-
Optional: true,
37-
ElementType: types.StringType,
38-
PlanModifiers: []planmodifier.Set{
39-
setplanmodifier.RequiresReplace(),
35+
attributeReplaceSchema := pb.NewResource(pb.NewResourceArgs{
36+
ResourceSchema: rschema.Schema{
37+
Attributes: map[string]rschema.Attribute{
38+
"key": rschema.SetAttribute{
39+
Optional: true,
40+
ElementType: types.StringType,
41+
PlanModifiers: []planmodifier.Set{
42+
setplanmodifier.RequiresReplace(),
43+
},
4044
},
4145
},
4246
},
43-
}
47+
})
4448

45-
nestedAttributeSchema := rschema.Schema{
46-
Attributes: map[string]rschema.Attribute{
47-
"key": rschema.SetNestedAttribute{
48-
Optional: true,
49-
NestedObject: rschema.NestedAttributeObject{
50-
Attributes: map[string]rschema.Attribute{
51-
"nested": rschema.StringAttribute{Optional: true},
49+
nestedAttributeSchema := pb.NewResource(pb.NewResourceArgs{
50+
ResourceSchema: rschema.Schema{
51+
Attributes: map[string]rschema.Attribute{
52+
"key": rschema.SetNestedAttribute{
53+
Optional: true,
54+
NestedObject: rschema.NestedAttributeObject{
55+
Attributes: map[string]rschema.Attribute{
56+
"nested": rschema.StringAttribute{Optional: true},
57+
},
5258
},
5359
},
5460
},
5561
},
56-
}
62+
})
5763

58-
nestedAttributeReplaceSchema := rschema.Schema{
59-
Attributes: map[string]rschema.Attribute{
60-
"key": rschema.SetNestedAttribute{
61-
Optional: true,
62-
NestedObject: rschema.NestedAttributeObject{
63-
Attributes: map[string]rschema.Attribute{
64-
"nested": rschema.StringAttribute{Optional: true},
64+
nestedAttributeReplaceSchema := pb.NewResource(pb.NewResourceArgs{
65+
ResourceSchema: rschema.Schema{
66+
Attributes: map[string]rschema.Attribute{
67+
"key": rschema.SetNestedAttribute{
68+
Optional: true,
69+
NestedObject: rschema.NestedAttributeObject{
70+
Attributes: map[string]rschema.Attribute{
71+
"nested": rschema.StringAttribute{Optional: true},
72+
},
73+
},
74+
PlanModifiers: []planmodifier.Set{
75+
setplanmodifier.RequiresReplace(),
6576
},
66-
},
67-
PlanModifiers: []planmodifier.Set{
68-
setplanmodifier.RequiresReplace(),
6977
},
7078
},
7179
},
72-
}
80+
})
7381

74-
nestedAttributeNestedReplaceSchema := rschema.Schema{
75-
Attributes: map[string]rschema.Attribute{
76-
"key": rschema.SetNestedAttribute{
77-
Optional: true,
78-
NestedObject: rschema.NestedAttributeObject{
79-
Attributes: map[string]rschema.Attribute{
80-
"nested": rschema.StringAttribute{
81-
Optional: true,
82-
PlanModifiers: []planmodifier.String{
83-
stringplanmodifier.RequiresReplace(),
82+
nestedAttributeNestedReplaceSchema := pb.NewResource(pb.NewResourceArgs{
83+
ResourceSchema: rschema.Schema{
84+
Attributes: map[string]rschema.Attribute{
85+
"key": rschema.SetNestedAttribute{
86+
Optional: true,
87+
NestedObject: rschema.NestedAttributeObject{
88+
Attributes: map[string]rschema.Attribute{
89+
"nested": rschema.StringAttribute{
90+
Optional: true,
91+
PlanModifiers: []planmodifier.String{
92+
stringplanmodifier.RequiresReplace(),
93+
},
8494
},
8595
},
8696
},
8797
},
8898
},
8999
},
90-
}
100+
})
91101

92-
blockSchema := rschema.Schema{
93-
Blocks: map[string]rschema.Block{
94-
"key": rschema.SetNestedBlock{
95-
NestedObject: rschema.NestedBlockObject{
96-
Attributes: map[string]rschema.Attribute{
97-
"nested": rschema.StringAttribute{Optional: true},
102+
blockSchema := pb.NewResource(pb.NewResourceArgs{
103+
ResourceSchema: rschema.Schema{
104+
Blocks: map[string]rschema.Block{
105+
"key": rschema.SetNestedBlock{
106+
NestedObject: rschema.NestedBlockObject{
107+
Attributes: map[string]rschema.Attribute{
108+
"nested": rschema.StringAttribute{Optional: true},
109+
},
98110
},
99111
},
100112
},
101113
},
102-
}
114+
})
103115

104-
blockReplaceSchema := rschema.Schema{
105-
Blocks: map[string]rschema.Block{
106-
"key": rschema.SetNestedBlock{
107-
NestedObject: rschema.NestedBlockObject{
108-
Attributes: map[string]rschema.Attribute{
109-
"nested": rschema.StringAttribute{
110-
Optional: true,
116+
blockReplaceSchema := pb.NewResource(pb.NewResourceArgs{
117+
ResourceSchema: rschema.Schema{
118+
Blocks: map[string]rschema.Block{
119+
"key": rschema.SetNestedBlock{
120+
NestedObject: rschema.NestedBlockObject{
121+
Attributes: map[string]rschema.Attribute{
122+
"nested": rschema.StringAttribute{
123+
Optional: true,
124+
},
111125
},
112126
},
113-
},
114-
PlanModifiers: []planmodifier.Set{
115-
setplanmodifier.RequiresReplace(),
127+
PlanModifiers: []planmodifier.Set{
128+
setplanmodifier.RequiresReplace(),
129+
},
116130
},
117131
},
118132
},
119-
}
133+
})
120134

121-
blockNestedReplaceSchema := rschema.Schema{
122-
Blocks: map[string]rschema.Block{
123-
"key": rschema.SetNestedBlock{
124-
NestedObject: rschema.NestedBlockObject{
125-
Attributes: map[string]rschema.Attribute{
126-
"nested": rschema.StringAttribute{
127-
Optional: true,
128-
PlanModifiers: []planmodifier.String{
129-
stringplanmodifier.RequiresReplace(),
135+
blockNestedReplaceSchema := pb.NewResource(pb.NewResourceArgs{
136+
ResourceSchema: rschema.Schema{
137+
Blocks: map[string]rschema.Block{
138+
"key": rschema.SetNestedBlock{
139+
NestedObject: rschema.NestedBlockObject{
140+
Attributes: map[string]rschema.Attribute{
141+
"nested": rschema.StringAttribute{
142+
Optional: true,
143+
PlanModifiers: []planmodifier.String{
144+
stringplanmodifier.RequiresReplace(),
145+
},
130146
},
131147
},
132148
},
133149
},
134150
},
135151
},
136-
}
152+
})
137153

138154
computedCreateFunc := func(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
139155
type Nested struct {
@@ -344,9 +360,28 @@ func TestDetailedDiffSet(t *testing.T) {
344360
return cty.ListVal(slice)
345361
}
346362

363+
nestedAttrListWithComputedSpecified := func(arr *[]string) cty.Value {
364+
if arr == nil {
365+
return cty.NullVal(cty.DynamicPseudoType)
366+
}
367+
slice := make([]cty.Value, len(*arr))
368+
for i, v := range *arr {
369+
slice[i] = cty.ObjectVal(
370+
map[string]cty.Value{
371+
"nested": cty.StringVal(v),
372+
"computed": cty.StringVal("non-computed-" + v),
373+
},
374+
)
375+
}
376+
if len(slice) == 0 {
377+
return cty.ListValEmpty(cty.Object(map[string]cty.Type{"nested": cty.String}))
378+
}
379+
return cty.ListVal(slice)
380+
}
381+
347382
schemaValueMakerPairs := []struct {
348383
name string
349-
schema rschema.Schema
384+
res pb.Resource
350385
valueMaker func(*[]string) cty.Value
351386
}{
352387
{"attribute no replace", attributeSchema, attrList},
@@ -420,10 +455,7 @@ func TestDetailedDiffSet(t *testing.T) {
420455
initialValue := schemaValueMakerPair.valueMaker(scenario.initialValue)
421456
changeValue := schemaValueMakerPair.valueMaker(scenario.changeValue)
422457

423-
res := pb.NewResource(pb.NewResourceArgs{
424-
ResourceSchema: schemaValueMakerPair.schema,
425-
})
426-
diff := crosstests.Diff(t, res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue})
458+
diff := crosstests.Diff(t, schemaValueMakerPair.res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue})
427459

428460
autogold.ExpectFile(t, testOutput{
429461
initialValue: scenario.initialValue,

0 commit comments

Comments
 (0)