-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PF provider_server detailed diff handling (#2628)
This change fixes an issue with the `provider_server` implementation's detailed diff handling. Previously passing a detailed diff to it would result in the previews being deleted. This is tested as part of #2629 The problem was that we were re-calculating the `diffs` and `replaces` keys for the GRPC Diff protocol in the `provider_server` implementation but also doing that incorrectly. Instead this change now makes `provider_server`'s `marshalDiff` just pass through the `diffs` and `replaces` which we have already calculated in https://github.com/pulumi/pulumi-terraform-bridge/blob/1d6b032f3e376af4667c6c4d80a65eff072df807/pkg/pf/tfbridge/provider_diff.go#L108-L109 fixes #2620
- Loading branch information
1 parent
bc33162
commit ea35eb2
Showing
2 changed files
with
124 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package plugin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin" | ||
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMarshalDiff(t *testing.T) { | ||
t.Parallel() | ||
|
||
runTest := func(t *testing.T, diff plugin.DiffResult) *pulumirpc.DiffResponse { | ||
server := providerServer{} | ||
resp, err := server.marshalDiff(diff) | ||
require.NoError(t, err) | ||
return resp | ||
} | ||
|
||
t.Run("no diffs", func(t *testing.T) { | ||
diff := plugin.DiffResult{ | ||
Changes: plugin.DiffNone, | ||
ReplaceKeys: []resource.PropertyKey{}, | ||
ChangedKeys: []resource.PropertyKey{}, | ||
DetailedDiff: map[string]plugin.PropertyDiff{}, | ||
} | ||
|
||
require.Equal(t, &pulumirpc.DiffResponse{ | ||
Replaces: []string{}, | ||
Changes: pulumirpc.DiffResponse_DIFF_NONE, | ||
Diffs: []string{}, | ||
}, runTest(t, diff)) | ||
}) | ||
|
||
t.Run("diff without detailed diff", func(t *testing.T) { | ||
diff := plugin.DiffResult{ | ||
Changes: plugin.DiffSome, | ||
ReplaceKeys: []resource.PropertyKey{"replace"}, | ||
ChangedKeys: []resource.PropertyKey{"change"}, | ||
} | ||
|
||
require.Equal(t, &pulumirpc.DiffResponse{ | ||
Replaces: []string{"replace"}, | ||
Changes: pulumirpc.DiffResponse_DIFF_SOME, | ||
Diffs: []string{"change"}, | ||
}, runTest(t, diff)) | ||
}) | ||
|
||
t.Run("diff with detailed diff", func(t *testing.T) { | ||
diff := plugin.DiffResult{ | ||
Changes: plugin.DiffSome, | ||
ReplaceKeys: []resource.PropertyKey{"replace"}, | ||
ChangedKeys: []resource.PropertyKey{"change", "replace"}, | ||
DetailedDiff: map[string]plugin.PropertyDiff{ | ||
"change": { | ||
Kind: plugin.DiffAdd, | ||
}, | ||
"replace": { | ||
Kind: plugin.DiffDeleteReplace, | ||
}, | ||
}, | ||
} | ||
|
||
require.Equal(t, &pulumirpc.DiffResponse{ | ||
Replaces: []string{ | ||
"replace", | ||
}, | ||
Changes: pulumirpc.DiffResponse_DIFF_SOME, | ||
Diffs: []string{ | ||
"change", | ||
"replace", | ||
}, | ||
DetailedDiff: map[string]*pulumirpc.PropertyDiff{ | ||
"change": {}, | ||
"replace": {Kind: pulumirpc.PropertyDiff_DELETE_REPLACE}, | ||
}, | ||
HasDetailedDiff: true, | ||
}, runTest(t, diff)) | ||
}) | ||
} |