-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Full fidelity SDKv2 crosstest.Create
equality
#2840
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,10 @@ package crosstests | |
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
|
@@ -118,11 +120,22 @@ func Create( | |
require.True(t, puResult.wasSet, "pulumi test was not set") | ||
|
||
// Compare the result | ||
|
||
assert.Equal(t, tfResult.meta, puResult.meta, | ||
"assert that both providers were configured with the same provider metadata") | ||
|
||
assertResourceDataEqual(t, resourceSchema, tfResult.data, puResult.data) | ||
if assert.True(t, tfResult.wasSet) && assert.True(t, puResult.wasSet) { | ||
assert.Equal(t, tfResult.meta, puResult.meta, "meta") | ||
// Use cmp to check if data is equal. We need to use cmp instead of | ||
// `assert`'s default `reflect.DeepEqual` because cmp treats identical | ||
// function pointers as equal, but `reflect.DeepEqual` does not. | ||
opts := []cmp.Option{ | ||
cmp.Exporter(func(reflect.Type) bool { return true }), | ||
cmp.Comparer(func(x, y schema.SchemaStateFunc) bool { | ||
return reflect.ValueOf(x).Pointer() == reflect.ValueOf(y).Pointer() | ||
}), | ||
Comment on lines
+130
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implements pointer equality for |
||
} | ||
if !cmp.Equal(tfResult.data, puResult.data, opts...) { | ||
t.Logf("Diff: %s", cmp.Diff(tfResult.data, puResult.data, opts...)) | ||
t.Fail() | ||
} | ||
} | ||
} | ||
|
||
type createOpts struct { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -637,11 +637,26 @@ func (s *grpcServer) ApplyResourceChange( | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var providerMetaVal []byte | ||
if providerMeta != nil { | ||
providerMetaVal, err = msgpack.Marshal(*providerMeta, providerMeta.Type()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
providerMetaVal, err = msgpack.Marshal(cty.NullVal(cty.EmptyObject), cty.EmptyObject) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
Comment on lines
+641
to
+652
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous compare function wasn't catching this, but the new comparison does. This now more accurately imitates TF. |
||
|
||
req := &tfprotov5.ApplyResourceChangeRequest{ | ||
TypeName: typeName, | ||
Config: &tfprotov5.DynamicValue{MsgPack: configVal}, | ||
PriorState: &tfprotov5.DynamicValue{MsgPack: priorStateVal}, | ||
PlannedState: &tfprotov5.DynamicValue{MsgPack: plannedStateVal}, | ||
ProviderMeta: &tfprotov5.DynamicValue{MsgPack: providerMetaVal}, | ||
} | ||
if len(plannedMeta) > 0 { | ||
plannedPrivate, err := json.Marshal(plannedMeta) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has
cmp
compare all un-exported fields.