Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Nov 20, 2024
1 parent e9d7ff7 commit 3e81b9c
Showing 1 changed file with 109 additions and 77 deletions.
186 changes: 109 additions & 77 deletions pkg/pf/tests/diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,119 +21,135 @@ import (
func TestDetailedDiffSet(t *testing.T) {
t.Parallel()

attributeSchema := rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetAttribute{
Optional: true,
ElementType: types.StringType,
attributeSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetAttribute{
Optional: true,
ElementType: types.StringType,
},
},
},
}
})

attributeReplaceSchema := rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetAttribute{
Optional: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
attributeReplaceSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetAttribute{
Optional: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
},
},
},
}
})

nestedAttributeSchema := rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetNestedAttribute{
Optional: true,
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{Optional: true},
nestedAttributeSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetNestedAttribute{
Optional: true,
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{Optional: true},
},
},
},
},
},
}
})

nestedAttributeReplaceSchema := rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetNestedAttribute{
Optional: true,
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{Optional: true},
nestedAttributeReplaceSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetNestedAttribute{
Optional: true,
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{Optional: true},
},
},
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
},
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
},
},
}
})

nestedAttributeNestedReplaceSchema := rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetNestedAttribute{
Optional: true,
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
nestedAttributeNestedReplaceSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.SetNestedAttribute{
Optional: true,
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
},
},
},
},
}
})

blockSchema := rschema.Schema{
Blocks: map[string]rschema.Block{
"key": rschema.SetNestedBlock{
NestedObject: rschema.NestedBlockObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{Optional: true},
blockSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Blocks: map[string]rschema.Block{
"key": rschema.SetNestedBlock{
NestedObject: rschema.NestedBlockObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{Optional: true},
},
},
},
},
},
}
})

blockReplaceSchema := rschema.Schema{
Blocks: map[string]rschema.Block{
"key": rschema.SetNestedBlock{
NestedObject: rschema.NestedBlockObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{
Optional: true,
blockReplaceSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Blocks: map[string]rschema.Block{
"key": rschema.SetNestedBlock{
NestedObject: rschema.NestedBlockObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{
Optional: true,
},
},
},
},
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
},
},
},
}
})

blockNestedReplaceSchema := rschema.Schema{
Blocks: map[string]rschema.Block{
"key": rschema.SetNestedBlock{
NestedObject: rschema.NestedBlockObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
blockNestedReplaceSchema := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: rschema.Schema{
Blocks: map[string]rschema.Block{
"key": rschema.SetNestedBlock{
NestedObject: rschema.NestedBlockObject{
Attributes: map[string]rschema.Attribute{
"nested": rschema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
},
},
},
},
}
})

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

nestedAttrListWithComputedSpecified := 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),
"computed": cty.StringVal("non-computed-" + 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
res pb.Resource
valueMaker func(*[]string) cty.Value
}{
{"attribute no replace", attributeSchema, attrList},
Expand Down Expand Up @@ -420,10 +455,7 @@ func TestDetailedDiffSet(t *testing.T) {
initialValue := schemaValueMakerPair.valueMaker(scenario.initialValue)
changeValue := schemaValueMakerPair.valueMaker(scenario.changeValue)

res := pb.NewResource(pb.NewResourceArgs{
ResourceSchema: schemaValueMakerPair.schema,
})
diff := crosstests.Diff(t, res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue})
diff := crosstests.Diff(t, schemaValueMakerPair.res, map[string]cty.Value{"key": initialValue}, map[string]cty.Value{"key": changeValue})

autogold.ExpectFile(t, testOutput{
initialValue: scenario.initialValue,
Expand Down

0 comments on commit 3e81b9c

Please sign in to comment.