Skip to content

Commit

Permalink
Fix TestAccServicePrinicpalHomeDeleteNotDeleted (#3075)
Browse files Browse the repository at this point in the history
* Fix service principal nightly test

* undo comment
  • Loading branch information
mgyucht authored Jan 8, 2024
1 parent 2fe11af commit 5269041
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
8 changes: 3 additions & 5 deletions internal/acceptance/service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func TestAccServicePrincipalHomeDeleteSuccess(t *testing.T) {

func TestAccServicePrinicpalHomeDeleteNotDeleted(t *testing.T) {
GetEnvOrSkipTest(t, "ARM_CLIENT_ID")
var appId string
workspaceLevel(t, step{
Template: `
resource "databricks_service_principal" "a" {
application_id = "{var.RANDOM_UUID}"
force_delete_home_dir = false
}`,
Check: func(s *terraform.State) error {
appId := s.RootModule().Resources["databricks_service_principal.a"].Primary.Attributes["application_id"]
os.Setenv("application_id_a", appId)
return nil
appId = s.RootModule().Resources["databricks_service_principal.a"].Primary.Attributes["application_id"]
return provisionHomeFolder(context.Background(), s, "databricks_service_principal.a", appId)
},
}, step{
Template: `
Expand All @@ -84,9 +84,7 @@ func TestAccServicePrinicpalHomeDeleteNotDeleted(t *testing.T) {
return err
}
ctx := context.Background()
appId := os.Getenv("application_id_a")
_, err = w.Workspace.GetStatusByPath(ctx, fmt.Sprintf("/Users/%v", appId))
os.Remove("application_id_a")
return err
},
})
Expand Down
32 changes: 15 additions & 17 deletions internal/acceptance/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ func TestAccUserHomeDelete(t *testing.T) {
})
}

func provisionHomeFolder(ctx context.Context, s *terraform.State, tfAttribute, username string) error {
client, err := client.New(&config.Config{})
if err != nil {
return err
}
userId := s.Modules[0].Resources[tfAttribute].Primary.ID
return client.Do(ctx, "PUT", fmt.Sprintf("/api/2.0/workspace/user/%s/homefolder", userId), nil, map[string]any{
"user": map[string]any{
"user_id": userId,
"username": username,
},
}, nil)
}

func TestAccUserHomeDeleteNotDeleted(t *testing.T) {
username := qa.RandomEmail()
workspaceLevel(t, step{
Expand All @@ -104,23 +118,7 @@ func TestAccUserHomeDeleteNotDeleted(t *testing.T) {
user_name = "` + username + `"
}`,
Check: func(s *terraform.State) error {
client, err := client.New(&config.Config{})
if err != nil {
return err
}
ctx := context.Background()
// Force creation of the home folder in case it is lazy
userId := s.Modules[0].Resources["databricks_user.a"].Primary.ID
err = client.Do(ctx, "PUT", fmt.Sprintf("/api/2.0/workspace/user/%s/homefolder", userId), nil, map[string]any{
"user": map[string]any{
"user_id": userId,
"username": username,
},
}, nil)
if err != nil {
return err
}
return nil
return provisionHomeFolder(context.Background(), s, "databricks_user.a", username)
},
}, step{
Template: `
Expand Down

0 comments on commit 5269041

Please sign in to comment.