From 88608c1c13ed7ff3ad93f982ec0af9ac1485f29d Mon Sep 17 00:00:00 2001 From: dgomez04 Date: Fri, 1 Nov 2024 12:01:23 -0600 Subject: [PATCH] removed unnecesary tests, switched to use a filter field to leverage REST API's flexibility --- .../pluginfw/resources/user/data_users.go | 11 +++++++---- .../resources/user/data_users_acc_test.go | 2 +- .../resources/user/data_users_test.go | 19 ------------------- 3 files changed, 8 insertions(+), 24 deletions(-) delete mode 100755 internal/providers/pluginfw/resources/user/data_users_test.go diff --git a/internal/providers/pluginfw/resources/user/data_users.go b/internal/providers/pluginfw/resources/user/data_users.go index c5fbdc8f6..ce15767cc 100644 --- a/internal/providers/pluginfw/resources/user/data_users.go +++ b/internal/providers/pluginfw/resources/user/data_users.go @@ -2,7 +2,6 @@ package user import ( "context" - "go/types" "github.com/databricks/databricks-sdk-go/service/iam" "github.com/databricks/terraform-provider-databricks/common" @@ -12,6 +11,7 @@ import ( "github.com/databricks/terraform-provider-databricks/internal/service/iam_tf" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" ) func DataSourceUsers() datasource.DataSource { @@ -55,6 +55,9 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest, return } + var users []iam.User + var err error + if d.Client.Config.IsAccountClient() { a, diags := d.Client.GetAccountClient() resp.Diagnostics.Append(diags...) @@ -62,7 +65,7 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest, return } - users, err := a.Users.ListAll(ctx, iam.ListAccountUsersRequest{Filter: usersInfo.Filter}) + users, err = a.Users.ListAll(ctx, iam.ListAccountUsersRequest{Filter: usersInfo.Filter.ValueString()}) if err != nil { resp.Diagnostics.AddError("Error listing account users", err.Error()) } @@ -73,7 +76,7 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest, return } - users, err := w.Users.ListAll(ctx, iam.ListUsersRequest{Filter: filter}) + users, err = w.Users.ListAll(ctx, iam.ListUsersRequest{Filter: usersInfo.Filter.ValueString()}) if err != nil { resp.Diagnostics.AddError("Error listing workspace users", err.Error()) } @@ -85,7 +88,7 @@ func (d *UsersDataSource) Read(ctx context.Context, req datasource.ReadRequest, if resp.Diagnostics.HasError() { return } - usersInfo.Users = append(usersInfo.Users, user) + usersInfo.Users = append(usersInfo.Users, tfUser) } resp.Diagnostics.Append(resp.State.Set(ctx, usersInfo)...) diff --git a/internal/providers/pluginfw/resources/user/data_users_acc_test.go b/internal/providers/pluginfw/resources/user/data_users_acc_test.go index eb76926b1..a71b8cd9e 100644 --- a/internal/providers/pluginfw/resources/user/data_users_acc_test.go +++ b/internal/providers/pluginfw/resources/user/data_users_acc_test.go @@ -19,7 +19,7 @@ const dataSourceTemplate = ` } data "databricks_users" "this" { - user_name_contains = "testuser" + filter = "userName co \"testuser\"" depends_on = [databricks_user.user1, databricks_user.user2] } ` diff --git a/internal/providers/pluginfw/resources/user/data_users_test.go b/internal/providers/pluginfw/resources/user/data_users_test.go deleted file mode 100755 index 08be8522d..000000000 --- a/internal/providers/pluginfw/resources/user/data_users_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package user - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/stretchr/testify/assert" -) - -func TestValidateFilters(t *testing.T) { - userInfo := UsersInfo{ - DisplayNameContains: "filter", - UserNameContains: "another_filter", - } - actualDiagnostics := validateFilters(&userInfo) - expectedDiagnostics := diag.Diagnostics{diag.NewErrorDiagnostic("Invalid configuration", "Exactly one of display_name_contains or user_name_contains should be specified, not both.")} - assert.True(t, actualDiagnostics.HasError()) - assert.Equal(t, expectedDiagnostics, actualDiagnostics) -}