Skip to content

Commit

Permalink
added resource definition to sdkv2 and acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomez04 committed Oct 9, 2024
1 parent e4aecf0 commit 8784d4c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions internal/acceptance/data_notification_destinations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package acceptance

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const dataSourceTemplate = `
resource "databricks_notification_destination" "email_notification" {
display_name = "email notification destination"
config {
email {
addresses = ["abc@gmail.com"]
}
}
}
resource "databricks_notification_destination" "notification" {
display_name = "slack notification destination"
config {
slack {
url = "https://hooks.slack.com/services/..."
}
}
}
data "databricks_notification_destinations" "this" {}
`

func checkNotificationsDestinationsDataSourcePopulated(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
ds, ok := s.Modules[0].Resources["data.databricks_notification_destinations.this"]
require.True(t, ok, "data.databricks_notification_destinations.this has to be there")

notificationCount := ds.Primary.Attributes["notification_destinations.#"]
require.Equal(t, "2", notificationCount, "expected two notifications")

notificationIds := []string{
ds.Primary.Attributes["notification_destinations.0.id"],
ds.Primary.Attributes["notification_destinations.1.id"],
}

expectedNotificationIds := []string{
s.Modules[0].Resources["databricks_notification_destination.email_notification"].Primary.ID,
s.Modules[0].Resources["databricks_notification_destination.slack_notification"].Primary.ID,
}

assert.ElementsMatch(t, expectedNotificationIds, notificationIds, "expected notification_destination ids to match")

return nil
}
}

func TestWorkspaceDataSourceNotificationDestination(t *testing.T) {
workspaceLevel(t, Step{
Template: dataSourceTemplate,
Check: checkNotificationsDestinationsDataSourcePopulated(t),
})
}
1 change: 1 addition & 0 deletions internal/providers/sdkv2/sdkv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func DatabricksProvider() *schema.Provider {
"databricks_mws_credentials": mws.DataSourceMwsCredentials().ToResource(),
"databricks_mws_workspaces": mws.DataSourceMwsWorkspaces().ToResource(),
"databricks_node_type": clusters.DataSourceNodeType().ToResource(),
"databricks_notification_destinations": settings.DataSourceNotificationDestinations().ToResource(),
"databricks_notebook": workspace.DataSourceNotebook().ToResource(),
"databricks_notebook_paths": workspace.DataSourceNotebookPaths().ToResource(),
"databricks_pipelines": pipelines.DataSourcePipelines().ToResource(),
Expand Down

0 comments on commit 8784d4c

Please sign in to comment.