@@ -21,119 +21,135 @@ import (
21
21
func TestDetailedDiffSet (t * testing.T ) {
22
22
t .Parallel ()
23
23
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
+ },
29
31
},
30
32
},
31
- }
33
+ })
32
34
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
+ },
40
44
},
41
45
},
42
46
},
43
- }
47
+ })
44
48
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
+ },
52
58
},
53
59
},
54
60
},
55
61
},
56
- }
62
+ })
57
63
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 (),
65
76
},
66
- },
67
- PlanModifiers : []planmodifier.Set {
68
- setplanmodifier .RequiresReplace (),
69
77
},
70
78
},
71
79
},
72
- }
80
+ })
73
81
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
+ },
84
94
},
85
95
},
86
96
},
87
97
},
88
98
},
89
99
},
90
- }
100
+ })
91
101
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
+ },
98
110
},
99
111
},
100
112
},
101
113
},
102
- }
114
+ })
103
115
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
+ },
111
125
},
112
126
},
113
- },
114
- PlanModifiers : []planmodifier. Set {
115
- setplanmodifier . RequiresReplace () ,
127
+ PlanModifiers : []planmodifier. Set {
128
+ setplanmodifier . RequiresReplace (),
129
+ } ,
116
130
},
117
131
},
118
132
},
119
- }
133
+ })
120
134
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
+ },
130
146
},
131
147
},
132
148
},
133
149
},
134
150
},
135
151
},
136
- }
152
+ })
137
153
138
154
computedCreateFunc := func (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
139
155
type Nested struct {
@@ -344,9 +360,28 @@ func TestDetailedDiffSet(t *testing.T) {
344
360
return cty .ListVal (slice )
345
361
}
346
362
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
+
347
382
schemaValueMakerPairs := []struct {
348
383
name string
349
- schema rschema. Schema
384
+ res pb. Resource
350
385
valueMaker func (* []string ) cty.Value
351
386
}{
352
387
{"attribute no replace" , attributeSchema , attrList },
@@ -420,10 +455,7 @@ func TestDetailedDiffSet(t *testing.T) {
420
455
initialValue := schemaValueMakerPair .valueMaker (scenario .initialValue )
421
456
changeValue := schemaValueMakerPair .valueMaker (scenario .changeValue )
422
457
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 })
427
459
428
460
autogold .ExpectFile (t , testOutput {
429
461
initialValue : scenario .initialValue ,
0 commit comments