Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 9 additions & 49 deletions pkg/pf/tests/diff_test/diff_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests"
)

func TestDetailedDiffList(t *testing.T) {
func TestPFDetailedDiffList(t *testing.T) {
t.Parallel()

attributeSchema := rschema.Schema{
Expand Down Expand Up @@ -133,51 +133,19 @@ func TestDetailedDiffList(t *testing.T) {
},
}

attrList := func(arr *[]string) cty.Value {
if arr == nil {
return cty.NullVal(cty.DynamicPseudoType)
}
slice := make([]cty.Value, len(*arr))
for i, v := range *arr {
slice[i] = cty.StringVal(v)
}
if len(slice) == 0 {
return cty.ListValEmpty(cty.String)
}
return cty.ListVal(slice)
}

nestedAttrList := func(arr *[]string) cty.Value {
if arr == nil {
return cty.NullVal(cty.DynamicPseudoType)
}
slice := make([]cty.Value, len(*arr))
for i, v := range *arr {
slice[i] = cty.ObjectVal(
map[string]cty.Value{
"nested": cty.StringVal(v),
},
)
}
if len(slice) == 0 {
return cty.ListValEmpty(cty.Object(map[string]cty.Type{"nested": cty.String}))
}
return cty.ListVal(slice)
}

schemaValueMakerPairs := []struct {
name string
schema rschema.Schema
valueMaker func(*[]string) cty.Value
}{
{"attribute no replace", attributeSchema, attrList},
{"attribute requires replace", attributeReplaceSchema, attrList},
{"nested attribute no replace", nestedAttributeSchema, nestedAttrList},
{"nested attribute requires replace", nestedAttributeReplaceSchema, nestedAttrList},
{"nested attribute nested requires replace", nestedAttributeNestedReplaceSchema, nestedAttrList},
{"block no replace", blockSchema, nestedAttrList},
{"block requires replace", blockReplaceSchema, nestedAttrList},
{"block nested requires replace", blockNestedReplaceSchema, nestedAttrList},
{"attribute no replace", attributeSchema, listValueMaker},
{"attribute requires replace", attributeReplaceSchema, listValueMaker},
{"nested attribute no replace", nestedAttributeSchema, nestedListValueMaker},
{"nested attribute requires replace", nestedAttributeReplaceSchema, nestedListValueMaker},
{"nested attribute nested requires replace", nestedAttributeNestedReplaceSchema, nestedListValueMaker},
{"block no replace", blockSchema, nestedListValueMaker},
{"block requires replace", blockReplaceSchema, nestedListValueMaker},
{"block nested requires replace", blockNestedReplaceSchema, nestedListValueMaker},
}

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

type testOutput struct {
initialValue *[]string
changeValue *[]string
tfOut string
pulumiOut string
detailedDiff map[string]any
}

for _, schemaValueMakerPair := range schemaValueMakerPairs {
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
t.Parallel()
Expand Down
10 changes: 1 addition & 9 deletions pkg/pf/tests/diff_test/diff_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests"
)

func TestDetailedDiffMap(t *testing.T) {
func TestPFDetailedDiffMap(t *testing.T) {
t.Parallel()

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

type testOutput struct {
initialValue *map[string]*string
changeValue *map[string]*string
tfOut string
pulumiOut string
detailedDiff map[string]any
}

for _, schemaValueMakerPair := range schemaValueMakerPairs {
t.Run(schemaValueMakerPair.name, func(t *testing.T) {
t.Parallel()
Expand Down
34 changes: 1 addition & 33 deletions pkg/pf/tests/diff_test/diff_object_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package tfbridgetests

import (
"context"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-framework/attr"
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
Expand All @@ -20,29 +18,7 @@ import (
crosstests "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/cross-tests"
)

type objectDefault basetypes.ObjectValue

var _ defaults.Object = objectDefault{}

func (o objectDefault) DefaultObject(ctx context.Context, req defaults.ObjectRequest, resp *defaults.ObjectResponse) {
resp.PlanValue = basetypes.ObjectValue(o)
}

func (o objectDefault) PlanModifyObject(ctx context.Context, req planmodifier.ObjectRequest, resp *planmodifier.ObjectResponse) {
if req.PlanValue.IsNull() || req.PlanValue.IsUnknown() {
resp.PlanValue = basetypes.ObjectValue(o)
}
}

func (o objectDefault) Description(ctx context.Context) string {
return "description"
}

func (o objectDefault) MarkdownDescription(ctx context.Context) string {
return "markdown description"
}

func TestDetailedDiffObject(t *testing.T) {
func TestPFDetailedDiffObject(t *testing.T) {
t.Parallel()

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

type testOutput struct {
initialValue *map[string]string
changeValue *map[string]string
tfOut string
pulumiOut string
detailedDiff map[string]any
}

for _, schema := range schemas {
t.Run(schema.name, func(t *testing.T) {
t.Parallel()
Expand Down
6 changes: 3 additions & 3 deletions pkg/pf/tests/diff_test/diff_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
)

func TestSecretBasic(t *testing.T) {
func TestPFSecretBasic(t *testing.T) {
t.Parallel()
provBuilder := providerbuilder.NewProvider(
providerbuilder.NewProviderArgs{
Expand Down Expand Up @@ -157,7 +157,7 @@ Resources:
})
}

func TestSecretObjectBlock(t *testing.T) {
func TestPFSecretObjectBlock(t *testing.T) {
t.Parallel()

provBuilder := pb.NewProvider(pb.NewProviderArgs{
Expand Down Expand Up @@ -258,7 +258,7 @@ Resources:
})
}

func TestSecretPulumiSchema(t *testing.T) {
func TestPFSecretPulumiSchema(t *testing.T) {
t.Parallel()

provBuilder := pb.NewProvider(pb.NewProviderArgs{
Expand Down
Loading
Loading