From 1a70870b3241d2355b34e66d470e80f8ac2a875c Mon Sep 17 00:00:00 2001 From: dgomez04 Date: Tue, 17 Sep 2024 16:24:46 -0600 Subject: [PATCH] #3468: added acceptance tests for data_users --- internal/acceptance/data_users_test.go | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 internal/acceptance/data_users_test.go diff --git a/internal/acceptance/data_users_test.go b/internal/acceptance/data_users_test.go new file mode 100644 index 0000000000..9c624e28d2 --- /dev/null +++ b/internal/acceptance/data_users_test.go @@ -0,0 +1,67 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestAccDataSourceDataUsers_DisplayNameContains(t *testing.T) { + accountLevel(t, step{ + Template: ` + data "databricks_data_users" "this" { + display_name_contains = "testuser" + }`, + Check: func(s *terraform.State) error { + r, ok := s.RootModule().Resources["data.databricks_data_users.this"] + if !ok { + return fmt.Errorf("data not found in state") + } + ids := r.Primary.Attributes["users.#"] + if ids == "" { + return fmt.Errorf("users is empty: %v", r.Primary.Attributes) + } + return nil + }, + }) +} + +func TestAccDataSourceDataUsers_UserNameContains(t *testing.T) { + accountLevel(t, step{ + Template: ` + data "databricks_data_users" "this" { + user_name_contains = "example.com" + }`, + Check: func(s *terraform.State) error { + r, ok := s.RootModule().Resources["data.databricks_data_users.this"] + if !ok { + return fmt.Errorf("data not found in state") + } + usersCount := r.Primary.Attributes["users.#"] + if usersCount == "" || usersCount == "0" { + return fmt.Errorf("users list is empty: %v", r.Primary.Attributes) + } + return nil + }, + }) +} + +func TestAccDataSourceDataUsers_NoFilters(t *testing.T) { + accountLevel(t, step{ + Template: ` + data "databricks_data_users" "this" { + }`, + Check: func(s *terraform.State) error { + r, ok := s.RootModule().Resources["data.databricks_data_users.this"] + if !ok { + return fmt.Errorf("data not found in state") + } + usersCount := r.Primary.Attributes["users.#"] + if usersCount == "" || usersCount == "0" { + return fmt.Errorf("users list is empty: %v", r.Primary.Attributes) + } + return nil + }, + }) +}