Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed Jun 15, 2023
1 parent 93f3b3e commit 4f6fd3e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 34 deletions.
12 changes: 12 additions & 0 deletions internal/acceptance/entitlements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestAccEntitlementResource(t *testing.T) {
allow_cluster_create = true
allow_instance_pool_create = true
}
resource "databricks_group" "third" {
display_name = "{var.RANDOM} group 2"
}
resource "databricks_entitlements" "first_entitlements" {
user_id = databricks_user.first.id
Expand All @@ -31,6 +35,14 @@ func TestAccEntitlementResource(t *testing.T) {
group_id = databricks_group.second.id
allow_cluster_create = true
allow_instance_pool_create = true
}
resource "databricks_entitlements" "third_entitlements" {
group_id = databricks_group.third.id
allow_cluster_create = false
allow_instance_pool_create = false
databricks_sql_access = false
workspace_access = false
}`
workspaceLevel(t, step{
Template: conf,
Expand Down
116 changes: 82 additions & 34 deletions scim/resource_entitlement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ var newGroup = Group{
},
}

var emptyGroup = Group{
Schemas: []URN{"urn:ietf:params:scim:schemas:core:2.0:Group"},
DisplayName: "Data Scientists",
ID: "abc",
}

var addRequest = PatchRequestComplexValue([]patchOperation{
{
"add", "entitlements", []ComplexValue{
"replace", "entitlements", []ComplexValue{
{
Value: "allow-cluster-create",
},
Expand All @@ -53,6 +59,16 @@ var addRequest = PatchRequestComplexValue([]patchOperation{
},
})

var emptyAddRequest = PatchRequestComplexValue([]patchOperation{
{
"replace", "entitlements", []ComplexValue{
{
Value: "",
},
},
},
})

var updateRequest = PatchRequestComplexValue([]patchOperation{
{
"remove", "entitlements", []ComplexValue{
Expand Down Expand Up @@ -85,20 +101,19 @@ var updateRequest = PatchRequestComplexValue([]patchOperation{
},
})

var deleteRequest = PatchRequestComplexValue([]patchOperation{{"remove", "entitlements", []ComplexValue{
var deleteRequest = PatchRequestComplexValue([]patchOperation{
{
Value: "allow-cluster-create",
"remove", "entitlements", []ComplexValue{
{
Value: "allow-cluster-create",
},
},
},
}}})
})

func TestResourceEntitlementsGroupCreate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups/abc?attributes=entitlements",
Response: oldGroup,
},
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/Groups/abc",
Expand Down Expand Up @@ -149,6 +164,29 @@ func TestResourceEntitlementsGroupRead(t *testing.T) {
})
}

func TestResourceEntitlementsGroupReadEmpty(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups/abc?attributes=entitlements",
Response: emptyGroup,
},
},
Resource: ResourceEntitlements(),
HCL: `group_id = "abc"`,
New: true,
Read: true,
ID: "group/abc",
}.ApplyAndExpectData(t, map[string]any{
"group_id": "abc",
"allow_cluster_create": false,
"workspace_access": false,
"allow_instance_pool_create": false,
"databricks_sql_access": false,
})
}

func TestResourceEntitlementsGroupRead_Error(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand All @@ -173,11 +211,6 @@ func TestResourceEntitlementsGroupRead_Error(t *testing.T) {
func TestResourceEntitlementsGroupUpdate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups/abc?attributes=entitlements",
Response: oldGroup,
},
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/Groups/abc",
Expand Down Expand Up @@ -313,11 +346,6 @@ var newUser = User{
func TestResourceEntitlementsUserCreate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=entitlements",
Response: oldUser,
},
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/Users/abc",
Expand Down Expand Up @@ -431,11 +459,6 @@ func TestResourceEntitlementsUserUpdate_Error(t *testing.T) {
func TestResourceEntitlementsUserUpdate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/abc?attributes=entitlements",
Response: oldUser,
},
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/Users/abc",
Expand Down Expand Up @@ -505,11 +528,6 @@ func TestResourceEntitlementsUserDelete(t *testing.T) {
func TestResourceEntitlementsSPNCreate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals/abc",
Response: oldUser,
},
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals/abc",
Expand Down Expand Up @@ -612,11 +630,6 @@ func TestResourceEntitlementsSPNRead_Error(t *testing.T) {
func TestResourceEntitlementsSPNUpdate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals/abc",
Response: oldUser,
},
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/ServicePrincipals/abc",
Expand Down Expand Up @@ -682,3 +695,38 @@ func TestResourceEntitlementsSPNDelete(t *testing.T) {
`,
}.ApplyNoError(t)
}

func TestResourceEntitlementsGroupCreateEmpty(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "PATCH",
Resource: "/api/2.0/preview/scim/v2/Groups/abc",
ExpectedRequest: emptyAddRequest,
Response: Group{
ID: "abc",
},
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Groups/abc?attributes=entitlements",
Response: emptyGroup,
},
},
Resource: ResourceEntitlements(),
HCL: `
group_id = "abc"
allow_instance_pool_create = false
allow_cluster_create = false
databricks_sql_access = false
workspace_access = false
`,
Create: true,
}.Apply(t)
assert.NoError(t, err)
assert.Equal(t, "group/abc", d.Id())
assert.Equal(t, false, d.Get("allow_cluster_create"))
assert.Equal(t, false, d.Get("allow_instance_pool_create"))
assert.Equal(t, false, d.Get("databricks_sql_access"))
assert.Equal(t, false, d.Get("workspace_access"))
}

0 comments on commit 4f6fd3e

Please sign in to comment.