@@ -6,13 +6,18 @@ import (
6
6
"regexp"
7
7
"testing"
8
8
9
+ "github.com/databrickslabs/databricks-terraform/client/model"
10
+ "github.com/databrickslabs/databricks-terraform/client/service"
9
11
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
12
+ "github.com/hashicorp/terraform-plugin-sdk/terraform"
13
+ "github.com/stretchr/testify/assert"
10
14
)
11
15
12
16
func TestAccAzureAdlsGen2Mount_correctly_mounts (t * testing.T ) {
13
17
terraformToApply := testAccAzureAdlsGen2Mount_correctly_mounts ()
14
18
15
19
resource .Test (t , resource.TestCase {
20
+ PreCheck : func () { testAccPreCheck (t ) },
16
21
Providers : testAccProviders ,
17
22
Steps : []resource.TestStep {
18
23
{
@@ -22,6 +27,29 @@ func TestAccAzureAdlsGen2Mount_correctly_mounts(t *testing.T) {
22
27
})
23
28
}
24
29
30
+ func TestAccAzureAdlsGen2Mount_cluster_deleted_correctly_mounts (t * testing.T ) {
31
+ terraformToApply := testAccAzureAdlsGen2Mount_correctly_mounts ()
32
+ var cluster model.ClusterInfo
33
+
34
+ resource .Test (t , resource.TestCase {
35
+ Providers : testAccProviders ,
36
+ Steps : []resource.TestStep {
37
+ {
38
+ Config : terraformToApply ,
39
+ Check : testClusterResourceExists ("databricks_cluster.cluster" , & cluster , t ),
40
+ },
41
+ {
42
+ PreConfig : func () {
43
+ client := testAccProvider .Meta ().(* service.DBApiClient )
44
+ err := client .Clusters ().Delete (cluster .ClusterID )
45
+ assert .NoError (t , err , err )
46
+ },
47
+ Config : terraformToApply ,
48
+ },
49
+ },
50
+ })
51
+ }
52
+
25
53
func TestAccAzureAdlsGen2Mount_capture_error (t * testing.T ) {
26
54
terraformToApply := testAccAzureAdlsGen2Mount_capture_error ()
27
55
@@ -39,7 +67,7 @@ func TestAccAzureAdlsGen2Mount_capture_error(t *testing.T) {
39
67
}
40
68
41
69
func testAccAzureAdlsGen2Mount_correctly_mounts () string {
42
- clientID := os .Getenv ("ARM_CLIENT_ID " )
70
+ clientID := os .Getenv ("DATABRICKS_AZURE_CLIENT_ID " )
43
71
clientSecret := os .Getenv ("ARM_CLIENT_SECRET" )
44
72
tenantID := os .Getenv ("ARM_TENANT_ID" )
45
73
subscriptionID := os .Getenv ("ARM_SUBSCRIPTION_ID" )
@@ -103,7 +131,7 @@ func testAccAzureAdlsGen2Mount_correctly_mounts() string {
103
131
}
104
132
105
133
func testAccAzureAdlsGen2Mount_capture_error () string {
106
- clientID := os .Getenv ("ARM_CLIENT_ID " )
134
+ clientID := os .Getenv ("DATABRICKS_AZURE_CLIENT_ID " )
107
135
clientSecret := os .Getenv ("ARM_CLIENT_SECRET" )
108
136
tenantID := os .Getenv ("ARM_TENANT_ID" )
109
137
subscriptionID := os .Getenv ("ARM_SUBSCRIPTION_ID" )
@@ -165,3 +193,23 @@ func testAccAzureAdlsGen2Mount_capture_error() string {
165
193
` , clientID , clientSecret , tenantID , subscriptionID , workspaceName , resourceGroupName , managedResourceGroupName , location , gen2AdalName )
166
194
return definition
167
195
}
196
+
197
+ // testClusterResourceExists queries the API and retrieves the matching Cluster.
198
+ func testClusterResourceExists (n string , cluster * model.ClusterInfo , t * testing.T ) resource.TestCheckFunc {
199
+ return func (s * terraform.State ) error {
200
+ // find the corresponding state object
201
+ rs , ok := s .RootModule ().Resources [n ]
202
+ if ! ok {
203
+ return fmt .Errorf ("Not found: %s" , n )
204
+ }
205
+
206
+ conn := testAccProvider .Meta ().(* service.DBApiClient )
207
+ resp , err := conn .Clusters ().Get (rs .Primary .ID )
208
+ if err != nil {
209
+ return err
210
+ }
211
+
212
+ * cluster = resp
213
+ return nil
214
+ }
215
+ }
0 commit comments