-
Notifications
You must be signed in to change notification settings - Fork 453
[Fix] Fixed syncing of effective fields in plugin framework implementation of share resource #4969
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
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -446,8 +446,13 @@ func (r *ShareResource) syncEffectiveFields(ctx context.Context, plan, state Sha | |
stateObjects, _ := state.GetObjects(ctx) | ||
finalObjects := []sharing_tf.SharedDataObject_SdkV2{} | ||
for i := range stateObjects { | ||
mode.objectLevel(ctx, &stateObjects[i], planObjects[i]) | ||
finalObjects = append(finalObjects, stateObjects[i]) | ||
for j := range planObjects { | ||
if stateObjects[i].Name == planObjects[j].Name { | ||
mode.objectLevel(ctx, &stateObjects[i], planObjects[j]) | ||
finalObjects = append(finalObjects, stateObjects[i]) | ||
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. what happens if the plan as an object which is not in the state? It seems that we are ignoring it. 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. Yes, we ignore it because in terraform we want to create the infra from the config 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. Can you explain a bit more what is what? I think I am mixing what stateObjects, planObjects and finalObjects are. |
||
break | ||
} | ||
} | ||
} | ||
state.SetObjects(ctx, finalObjects) | ||
return state, d | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package sharing | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/databricks-sdk-go/service/sharing" | ||
"github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/converters" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestShareSyncEffectiveFields(t *testing.T) { | ||
shareName := "test-share-name" | ||
ctx := context.Background() | ||
shares := ShareResource{} | ||
|
||
tests := []struct { | ||
name string | ||
planGoSDK sharing.ShareInfo | ||
stateGoSDK sharing.ShareInfo | ||
}{ | ||
{ | ||
name: "plan with less objects", | ||
planGoSDK: sharing.ShareInfo{ | ||
Name: shareName, | ||
Objects: []sharing.SharedDataObject{ | ||
{ | ||
Name: "obj-1", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-1"}}}, | ||
}, | ||
}, | ||
{ | ||
Name: "obj-3", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-3"}}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
stateGoSDK: sharing.ShareInfo{ | ||
Name: shareName, | ||
Objects: []sharing.SharedDataObject{ | ||
{ | ||
Name: "obj-1", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-1"}}}, | ||
}, | ||
}, | ||
{ | ||
Name: "obj-2", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-2"}}}, | ||
}, | ||
}, | ||
{ | ||
Name: "obj-3", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-3"}}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "plan with more objects", | ||
planGoSDK: sharing.ShareInfo{ | ||
Name: shareName, | ||
Objects: []sharing.SharedDataObject{ | ||
{ | ||
Name: "obj-1", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-1"}}}, | ||
}, | ||
}, | ||
{ | ||
Name: "obj-2", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-2"}}}, | ||
}, | ||
}, | ||
{ | ||
Name: "obj-3", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-3"}}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
stateGoSDK: sharing.ShareInfo{ | ||
Name: shareName, | ||
Objects: []sharing.SharedDataObject{ | ||
{ | ||
Name: "obj-1", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-1"}}}, | ||
}, | ||
}, | ||
{ | ||
Name: "obj-3", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-3"}}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "empty plan", | ||
planGoSDK: sharing.ShareInfo{ | ||
Name: shareName, | ||
Objects: []sharing.SharedDataObject{}, | ||
}, | ||
stateGoSDK: sharing.ShareInfo{ | ||
Name: shareName, | ||
Objects: []sharing.SharedDataObject{ | ||
{ | ||
Name: "obj-1", | ||
Partitions: []sharing.Partition{ | ||
{Values: []sharing.PartitionValue{{Value: "part-1"}}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var planTFSDK ShareInfoExtended | ||
diagnostics := converters.GoSdkToTfSdkStruct(ctx, tt.planGoSDK, &planTFSDK) | ||
assert.False(t, diagnostics.HasError()) | ||
|
||
var stateTFSDK ShareInfoExtended | ||
diagnostics = converters.GoSdkToTfSdkStruct(ctx, tt.stateGoSDK, &stateTFSDK) | ||
assert.False(t, diagnostics.HasError()) | ||
|
||
_, diagnostics = shares.syncEffectiveFields(ctx, planTFSDK, stateTFSDK, effectiveFieldsActionRead{}) | ||
assert.False(t, diagnostics.HasError()) | ||
}) | ||
} | ||
} |
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.
Are we suppressing the error? Can this fail?