Skip to content

Commit 723283b

Browse files
Refactor PF detailed diff tests
1 parent 89867cb commit 723283b

File tree

860 files changed

+295
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

860 files changed

+295
-286
lines changed

pkg/pf/tests/diff_test/diff_list_test.go

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests"
1717
)
1818

19-
func TestDetailedDiffList(t *testing.T) {
19+
func TestPFDetailedDiffList(t *testing.T) {
2020
t.Parallel()
2121

2222
attributeSchema := rschema.Schema{
@@ -133,51 +133,19 @@ func TestDetailedDiffList(t *testing.T) {
133133
},
134134
}
135135

136-
attrList := func(arr *[]string) cty.Value {
137-
if arr == nil {
138-
return cty.NullVal(cty.DynamicPseudoType)
139-
}
140-
slice := make([]cty.Value, len(*arr))
141-
for i, v := range *arr {
142-
slice[i] = cty.StringVal(v)
143-
}
144-
if len(slice) == 0 {
145-
return cty.ListValEmpty(cty.String)
146-
}
147-
return cty.ListVal(slice)
148-
}
149-
150-
nestedAttrList := func(arr *[]string) cty.Value {
151-
if arr == nil {
152-
return cty.NullVal(cty.DynamicPseudoType)
153-
}
154-
slice := make([]cty.Value, len(*arr))
155-
for i, v := range *arr {
156-
slice[i] = cty.ObjectVal(
157-
map[string]cty.Value{
158-
"nested": cty.StringVal(v),
159-
},
160-
)
161-
}
162-
if len(slice) == 0 {
163-
return cty.ListValEmpty(cty.Object(map[string]cty.Type{"nested": cty.String}))
164-
}
165-
return cty.ListVal(slice)
166-
}
167-
168136
schemaValueMakerPairs := []struct {
169137
name string
170138
schema rschema.Schema
171139
valueMaker func(*[]string) cty.Value
172140
}{
173-
{"attribute no replace", attributeSchema, attrList},
174-
{"attribute requires replace", attributeReplaceSchema, attrList},
175-
{"nested attribute no replace", nestedAttributeSchema, nestedAttrList},
176-
{"nested attribute requires replace", nestedAttributeReplaceSchema, nestedAttrList},
177-
{"nested attribute nested requires replace", nestedAttributeNestedReplaceSchema, nestedAttrList},
178-
{"block no replace", blockSchema, nestedAttrList},
179-
{"block requires replace", blockReplaceSchema, nestedAttrList},
180-
{"block nested requires replace", blockNestedReplaceSchema, nestedAttrList},
141+
{"attribute no replace", attributeSchema, listValueMaker},
142+
{"attribute requires replace", attributeReplaceSchema, listValueMaker},
143+
{"nested attribute no replace", nestedAttributeSchema, nestedListValueMaker},
144+
{"nested attribute requires replace", nestedAttributeReplaceSchema, nestedListValueMaker},
145+
{"nested attribute nested requires replace", nestedAttributeNestedReplaceSchema, nestedListValueMaker},
146+
{"block no replace", blockSchema, nestedListValueMaker},
147+
{"block requires replace", blockReplaceSchema, nestedListValueMaker},
148+
{"block nested requires replace", blockNestedReplaceSchema, nestedListValueMaker},
181149
}
182150

183151
longList := &[]string{}
@@ -214,14 +182,6 @@ func TestDetailedDiffList(t *testing.T) {
214182
{"long list added front", longList, &longListAddedFront},
215183
}
216184

217-
type testOutput struct {
218-
initialValue *[]string
219-
changeValue *[]string
220-
tfOut string
221-
pulumiOut string
222-
detailedDiff map[string]any
223-
}
224-
225185
for _, schemaValueMakerPair := range schemaValueMakerPairs {
226186
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
227187
t.Parallel()

pkg/pf/tests/diff_test/diff_map_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests"
1616
)
1717

18-
func TestDetailedDiffMap(t *testing.T) {
18+
func TestPFDetailedDiffMap(t *testing.T) {
1919
t.Parallel()
2020

2121
attributeSchema := pb.NewResource(pb.NewResourceArgs{
@@ -168,14 +168,6 @@ func TestDetailedDiffMap(t *testing.T) {
168168
// {"changed value non-null to null", &map[string]*string{"k": ref("value")}, &map[string]*string{"k": nil}},
169169
}
170170

171-
type testOutput struct {
172-
initialValue *map[string]*string
173-
changeValue *map[string]*string
174-
tfOut string
175-
pulumiOut string
176-
detailedDiff map[string]any
177-
}
178-
179171
for _, schemaValueMakerPair := range schemaValueMakerPairs {
180172
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
181173
t.Parallel()

pkg/pf/tests/diff_test/diff_object_test.go

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package tfbridgetests
22

33
import (
4-
"context"
54
"strings"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-framework/attr"
98
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
10-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults"
119
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
1210
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1311
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -20,29 +18,7 @@ import (
2018
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests"
2119
)
2220

23-
type objectDefault basetypes.ObjectValue
24-
25-
var _ defaults.Object = objectDefault{}
26-
27-
func (o objectDefault) DefaultObject(ctx context.Context, req defaults.ObjectRequest, resp *defaults.ObjectResponse) {
28-
resp.PlanValue = basetypes.ObjectValue(o)
29-
}
30-
31-
func (o objectDefault) PlanModifyObject(ctx context.Context, req planmodifier.ObjectRequest, resp *planmodifier.ObjectResponse) {
32-
if req.PlanValue.IsNull() || req.PlanValue.IsUnknown() {
33-
resp.PlanValue = basetypes.ObjectValue(o)
34-
}
35-
}
36-
37-
func (o objectDefault) Description(ctx context.Context) string {
38-
return "description"
39-
}
40-
41-
func (o objectDefault) MarkdownDescription(ctx context.Context) string {
42-
return "markdown description"
43-
}
44-
45-
func TestDetailedDiffObject(t *testing.T) {
21+
func TestPFDetailedDiffObject(t *testing.T) {
4622
t.Parallel()
4723

4824
attributeSchema := rschema.Schema{
@@ -318,14 +294,6 @@ func TestDetailedDiffObject(t *testing.T) {
318294
{"changed non-empty to empty", &map[string]string{"nested": "value"}, &map[string]string{}},
319295
}
320296

321-
type testOutput struct {
322-
initialValue *map[string]string
323-
changeValue *map[string]string
324-
tfOut string
325-
pulumiOut string
326-
detailedDiff map[string]any
327-
}
328-
329297
for _, schema := range schemas {
330298
t.Run(schema.name, func(t *testing.T) {
331299
t.Parallel()

pkg/pf/tests/diff_test/diff_secret_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
1818
)
1919

20-
func TestSecretBasic(t *testing.T) {
20+
func TestPFSecretBasic(t *testing.T) {
2121
t.Parallel()
2222
provBuilder := providerbuilder.NewProvider(
2323
providerbuilder.NewProviderArgs{
@@ -157,7 +157,7 @@ Resources:
157157
})
158158
}
159159

160-
func TestSecretObjectBlock(t *testing.T) {
160+
func TestPFSecretObjectBlock(t *testing.T) {
161161
t.Parallel()
162162

163163
provBuilder := pb.NewProvider(pb.NewProviderArgs{
@@ -258,7 +258,7 @@ Resources:
258258
})
259259
}
260260

261-
func TestSecretPulumiSchema(t *testing.T) {
261+
func TestPFSecretPulumiSchema(t *testing.T) {
262262
t.Parallel()
263263

264264
provBuilder := pb.NewProvider(pb.NewProviderArgs{

0 commit comments

Comments
 (0)