Skip to content

Commit b78a587

Browse files
committed
fix the update test
1 parent f5cb7bd commit b78a587

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

sumologic/resource_sumologic_permissions_test.go

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestAccPermission_create(t *testing.T) {
1717
CheckDestroy: testAccCheckPermissionDestroy,
1818
Steps: []resource.TestStep{
1919
{
20-
Config: testAccSumologicPermission(otherResource, false, "create", "View", "role"),
20+
Config: testAccSumologicPermission(otherResource, false, "create", "role", "sumologic_role.permission_test_role"),
2121
Check: resource.ComposeTestCheckFunc(
2222
testAccCheckPermissionExists("sumologic_content_permission.content_permission_test", &response, t),
2323
testAccCheckPermissionAttributes("sumologic_content_permission.content_permission_test"),
@@ -40,7 +40,7 @@ func TestAccPermission_update(t *testing.T) {
4040
CheckDestroy: testAccCheckPermissionDestroy,
4141
Steps: []resource.TestStep{
4242
{
43-
Config: testAccSumologicPermission(otherResource, false, "create", "View", "role"),
43+
Config: testAccSumologicPermission(otherResource, false, "create", "role", "sumologic_role.permission_test_role"),
4444
Check: resource.ComposeTestCheckFunc(
4545
testAccCheckPermissionExists("sumologic_content_permission.content_permission_test", &response, t),
4646
testAccCheckPermissionAttributes("sumologic_content_permission.content_permission_test"),
@@ -50,14 +50,14 @@ func TestAccPermission_update(t *testing.T) {
5050
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "permission.0.source_type", "role"),
5151
),
5252
}, {
53-
Config: testAccSumologicPermission(otherResource, true, "update", "Edit", "role"),
53+
Config: testAccSumologicPermissionUpdate(otherResource, true, "update", "user", "sumologic_user.permission_test_user"),
5454
Check: resource.ComposeTestCheckFunc(
5555
testAccCheckPermissionExists("sumologic_content_permission.content_permission_test", &response, t),
5656
testAccCheckPermissionAttributes("sumologic_content_permission.content_permission_test"),
5757
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "notify_recipient", "true"),
5858
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "notification_message", "update"),
59-
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "permission.0.permission_name", "Edit"),
60-
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "permission.0.source_type", "role"),
59+
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "permission.1.permission_name", "View"),
60+
resource.TestCheckResourceAttr("sumologic_content_permission.content_permission_test", "permission.1.source_type", "user"),
6161
),
6262
},
6363
},
@@ -73,7 +73,7 @@ func TestAccPermission_delete(t *testing.T) {
7373
CheckDestroy: testAccCheckPermissionDestroy,
7474
Steps: []resource.TestStep{
7575
{
76-
Config: testAccSumologicPermission(otherResource, false, "create", "View", "role"),
76+
Config: testAccSumologicPermission(otherResource, false, "create", "role", "sumologic_role.permission_test_role"),
7777
Check: resource.ComposeTestCheckFunc(
7878
testAccCheckPermissionExists("sumologic_content_permission.content_permission_test", &response, t),
7979
testAccCheckPermissionAttributes("sumologic_content_permission.content_permission_test"),
@@ -181,7 +181,7 @@ func testAccCheckPermissionAttributes(name string) resource.TestCheckFunc {
181181
}
182182
}
183183

184-
func testAccSumologicPermission(resource string, notify_recipient bool, notification_message string, permission_name string, source_type string) string {
184+
func testAccSumologicPermission(resource string, notify_recipient bool, notification_message string, source_type string, source_id string) string {
185185
return fmt.Sprintf(`
186186
%s
187187
@@ -190,13 +190,36 @@ func testAccSumologicPermission(resource string, notify_recipient bool, notifica
190190
notify_recipient = %t
191191
notification_message = "%s"
192192
permission {
193-
permission_name = "%s"
193+
permission_name = "View"
194194
source_type = "%s"
195+
source_id = %s.id
196+
}
197+
}
198+
199+
`, resource, notify_recipient, notification_message, source_type, source_id)
200+
}
201+
202+
func testAccSumologicPermissionUpdate(resource string, notify_recipient bool, notification_message string, source_type string, source_id string) string {
203+
return fmt.Sprintf(`
204+
%s
205+
206+
resource "sumologic_content_permission" "content_permission_test" {
207+
content_id = sumologic_content.permission_test_content.id
208+
notify_recipient = %t
209+
notification_message = "%s"
210+
permission {
211+
permission_name = "View"
212+
source_type = "role"
195213
source_id = sumologic_role.permission_test_role.id
196214
}
215+
permission {
216+
permission_name = "View"
217+
source_type = "%s"
218+
source_id = %s.id
219+
}
197220
}
198221
199-
`, resource, notify_recipient, notification_message, permission_name, source_type)
222+
`, resource, notify_recipient, notification_message, source_type, source_id)
200223
}
201224

202225
func testAccSumologicPermissionDelete() string {
@@ -220,4 +243,13 @@ resource "sumologic_role" "permission_test_role" {
220243
name = "permission_test_role"
221244
description = "Testing content permission resource"
222245
}
246+
247+
resource "sumologic_user" "permission_test_user" {
248+
first_name = "test"
249+
last_name = "permission"
250+
251+
is_active = true
252+
role_ids = [sumologic_role.permission_test_role.id]
253+
transfer_to = ""
254+
}
223255
`

0 commit comments

Comments
 (0)