@@ -17,13 +17,16 @@ func TestAccPermission_create(t *testing.T) {
1717 CheckDestroy : testAccCheckPermissionDestroy ,
1818 Steps : []resource.TestStep {
1919 {
20- Config : testAccSumologicPermission (otherResource , false , "create" , "role" , "sumologic_role.permission_test_role" ),
20+ Config : testAccSumologicPermission (
21+ otherResource , false , "create" , "role" , "sumologic_role.permission_test_role" ),
2122 Check : resource .ComposeTestCheckFunc (
2223 testAccCheckPermissionExists ("sumologic_content_permission.content_permission_test" , & response , t ),
2324 testAccCheckPermissionAttributes ("sumologic_content_permission.content_permission_test" ),
24- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notify_recipient" , "false" ),
25- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notification_message" , "create" ),
26- // need to figure out how to test TypeSet
25+ resource .TestCheckResourceAttr (
26+ "sumologic_content_permission.content_permission_test" , "notify_recipient" , "false" ),
27+ resource .TestCheckResourceAttr (
28+ "sumologic_content_permission.content_permission_test" , "notification_message" , "create" ),
29+ // Need to upgrade to plugin SDKv2 to test TypeSet objects
2730 ),
2831 },
2932 },
@@ -39,20 +42,26 @@ func TestAccPermission_update(t *testing.T) {
3942 CheckDestroy : testAccCheckPermissionDestroy ,
4043 Steps : []resource.TestStep {
4144 {
42- Config : testAccSumologicPermission (otherResource , false , "create" , "role" , "sumologic_role.permission_test_role" ),
45+ Config : testAccSumologicPermission (
46+ otherResource , false , "create" , "role" , "sumologic_role.permission_test_role" ),
4347 Check : resource .ComposeTestCheckFunc (
4448 testAccCheckPermissionExists ("sumologic_content_permission.content_permission_test" , & response , t ),
4549 testAccCheckPermissionAttributes ("sumologic_content_permission.content_permission_test" ),
46- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notify_recipient" , "false" ),
47- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notification_message" , "create" ),
50+ resource .TestCheckResourceAttr (
51+ "sumologic_content_permission.content_permission_test" , "notify_recipient" , "false" ),
52+ resource .TestCheckResourceAttr (
53+ "sumologic_content_permission.content_permission_test" , "notification_message" , "create" ),
4854 ),
4955 }, {
50- Config : testAccSumologicPermissionUpdate (otherResource , true , "update" , "user" , "sumologic_user.permission_test_user" ),
56+ Config : testAccSumologicPermissionUpdate (
57+ otherResource , true , "update" , "user" , "sumologic_user.permission_test_user" ),
5158 Check : resource .ComposeTestCheckFunc (
5259 testAccCheckPermissionExists ("sumologic_content_permission.content_permission_test" , & response , t ),
5360 testAccCheckPermissionAttributes ("sumologic_content_permission.content_permission_test" ),
54- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notify_recipient" , "true" ),
55- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notification_message" , "update" ),
61+ resource .TestCheckResourceAttr (
62+ "sumologic_content_permission.content_permission_test" , "notify_recipient" , "true" ),
63+ resource .TestCheckResourceAttr (
64+ "sumologic_content_permission.content_permission_test" , "notification_message" , "update" ),
5665 ),
5766 },
5867 },
@@ -68,12 +77,15 @@ func TestAccPermission_delete(t *testing.T) {
6877 CheckDestroy : testAccCheckPermissionDestroy ,
6978 Steps : []resource.TestStep {
7079 {
71- Config : testAccSumologicPermission (otherResource , false , "create" , "role" , "sumologic_role.permission_test_role" ),
80+ Config : testAccSumologicPermission (
81+ otherResource , false , "create" , "role" , "sumologic_role.permission_test_role" ),
7282 Check : resource .ComposeTestCheckFunc (
7383 testAccCheckPermissionExists ("sumologic_content_permission.content_permission_test" , & response , t ),
7484 testAccCheckPermissionAttributes ("sumologic_content_permission.content_permission_test" ),
75- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notify_recipient" , "false" ),
76- resource .TestCheckResourceAttr ("sumologic_content_permission.content_permission_test" , "notification_message" , "create" ),
85+ resource .TestCheckResourceAttr (
86+ "sumologic_content_permission.content_permission_test" , "notify_recipient" , "false" ),
87+ resource .TestCheckResourceAttr (
88+ "sumologic_content_permission.content_permission_test" , "notification_message" , "create" ),
7789 ),
7890 }, {
7991 Config : testAccSumologicPermissionDelete (),
@@ -94,15 +106,15 @@ func testAccCheckPermissionDestroy(s *terraform.State) error {
94106 }
95107
96108 if rs .Primary .ID == "" {
97- return fmt .Errorf ("CSE Chain Rule destruction check: CSE Chain Rule ID is not set" )
109+ return fmt .Errorf ("Content Permission ID is not set" )
98110 }
99111 id := rs .Primary .ID
100112 u , err := client .GetPermissions (id )
101113 if err != nil {
102114 return fmt .Errorf ("Encountered an error: " + err .Error ())
103115 }
104116 if u != nil {
105- return fmt .Errorf ("content still exists" )
117+ return fmt .Errorf ("Content and permissions still exists" )
106118 }
107119 }
108120 return nil
@@ -141,7 +153,8 @@ func testAccCheckPermissionDelete(name string) resource.TestCheckFunc {
141153 }
142154}
143155
144- func testAccCheckPermissionExists (name string , response * PermissionsResponse , t * testing.T ) resource.TestCheckFunc {
156+ func testAccCheckPermissionExists (name string , response * PermissionsResponse ,
157+ t * testing.T ) resource.TestCheckFunc {
145158 return func (s * terraform.State ) error {
146159 rs , ok := s .RootModule ().Resources [name ]
147160 if ! ok {
@@ -174,75 +187,76 @@ func testAccCheckPermissionAttributes(name string) resource.TestCheckFunc {
174187 }
175188}
176189
177- func testAccSumologicPermission (resource string , notify_recipient bool , notification_message string , source_type string , source_id string ) string {
190+ func testAccSumologicPermission (resource string , notify_recipient bool , notification_message string ,
191+ source_type string , source_id string ) string {
178192 return fmt .Sprintf (`
179- %s
180-
181- resource "sumologic_content_permission" "content_permission_test" {
182- content_id = sumologic_content.permission_test_content.id
183- notify_recipient = %t
184- notification_message = "%s"
185- permission {
186- permission_name = "View"
187- source_type = "%s"
188- source_id = %s.id
189- }
190- }
191-
192- ` , resource , notify_recipient , notification_message , source_type , source_id )
193+ %s
194+
195+ resource "sumologic_content_permission" "content_permission_test" {
196+ content_id = sumologic_content.permission_test_content.id
197+ notify_recipient = %t
198+ notification_message = "%s"
199+ permission {
200+ permission_name = "View"
201+ source_type = "%s"
202+ source_id = %s.id
203+ }
204+ }` ,
205+ resource , notify_recipient , notification_message , source_type , source_id ,
206+ )
193207}
194208
195- func testAccSumologicPermissionUpdate (resource string , notify_recipient bool , notification_message string , source_type string , source_id string ) string {
209+ func testAccSumologicPermissionUpdate (resource string , notify_recipient bool ,
210+ notification_message string , source_type string , source_id string ) string {
196211 return fmt .Sprintf (`
197- %s
198-
199- resource "sumologic_content_permission" "content_permission_test" {
200- content_id = sumologic_content.permission_test_content.id
201- notify_recipient = %t
202- notification_message = "%s"
203- permission {
204- permission_name = "View"
205- source_type = "role"
206- source_id = sumologic_role.permission_test_role.id
207- }
208- permission {
209- permission_name = "View"
210- source_type = "%s"
211- source_id = %s.id
212- }
213- }
214-
215- ` , resource , notify_recipient , notification_message , source_type , source_id )
212+ %s
213+
214+ resource "sumologic_content_permission" "content_permission_test" {
215+ content_id = sumologic_content.permission_test_content.id
216+ notify_recipient = %t
217+ notification_message = "%s"
218+ permission {
219+ permission_name = "View"
220+ source_type = "role"
221+ source_id = sumologic_role.permission_test_role.id
222+ }
223+ permission {
224+ permission_name = "View"
225+ source_type = "%s"
226+ source_id = %s.id
227+ }
228+ }` ,
229+ resource , notify_recipient , notification_message , source_type , source_id ,
230+ )
216231}
217232
218233func testAccSumologicPermissionDelete () string {
219234 return otherResource
220235}
221236
222237var otherResource = `
223- data "sumologic_personal_folder" "personalFolder" {}
224-
225- resource "sumologic_content" "permission_test_content" {
226- parent_id = data.sumologic_personal_folder.personalFolder.id
227- config = jsonencode({
228- "type": "FolderSyncDefinition",
229- "name": "test_permission_resource_folder",
230- "description": "",
231- "children": []
232- })
233- }
238+ data "sumologic_personal_folder" "personalFolder" {}
234239
235- resource "sumologic_role" "permission_test_role" {
236- name = "permission_test_role"
237- description = "Testing content permission resource"
238- }
240+ resource "sumologic_content" "permission_test_content" {
241+ parent_id = data.sumologic_personal_folder.personalFolder.id
242+ config = jsonencode({
243+ "type": "FolderSyncDefinition",
244+ "name": "test_permission_resource_folder",
245+ "description": "",
246+ "children": []
247+ })
248+ }
239249
240- resource "sumologic_user" "permission_test_user" {
241- first_name = "test"
242- last_name = "permission"
243- 244- is_active = true
245- role_ids = [sumologic_role.permission_test_role.id]
246- transfer_to = ""
247- }
248- `
250+ resource "sumologic_role" "permission_test_role" {
251+ name = "permission_test_role"
252+ description = "Testing content permission resource"
253+ }
254+
255+ resource "sumologic_user" "permission_test_user" {
256+ first_name = "test"
257+ last_name = "permission"
258+ 259+ is_active = true
260+ role_ids = [sumologic_role.permission_test_role.id]
261+ transfer_to = ""
262+ }`
0 commit comments