Skip to content

Commit

Permalink
databricks#3468: added acceptance tests for data_users
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomez04 committed Oct 22, 2024
1 parent 32a14f7 commit 1a70870
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions internal/acceptance/data_users_test.go
Original file line number Diff line number Diff line change
@@ -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
},
})
}

0 comments on commit 1a70870

Please sign in to comment.