@@ -3,8 +3,6 @@ package sumologic
33import (
44 "encoding/json"
55 "fmt"
6- "log"
7- "os"
86 "reflect"
97 "testing"
108
@@ -15,20 +13,17 @@ import (
1513//Testing create functionality for Content resources
1614func TestAccContentCreate (t * testing.T ) {
1715 var content Content
18- personalContentId := os .Getenv ("SUMOLOGIC_PF" )
1916
2017 resource .Test (t , resource.TestCase {
2118 PreCheck : func () { testAccPreCheck (t ) },
2219 Providers : testAccProviders ,
23- CheckDestroy : testAccCheckContentDestroy ,
20+ CheckDestroy : testAccCheckContentDestroy ( content ) ,
2421 Steps : []resource.TestStep {
2522 {
26- Config : testAccSumologicContent (personalContentId , configJson ),
23+ Config : testAccSumologicContent (configJson ),
2724 Check : resource .ComposeTestCheckFunc (
2825 testAccCheckContentExists ("sumologic_content.test" , & content , t ),
2926 testAccCheckContentAttributes ("sumologic_content.test" ),
30- // testAccCheckContentConfig(&content),
31- resource .TestCheckResourceAttr ("sumologic_content.test" , "parent_id" , personalContentId ),
3227 ),
3328 },
3429 },
@@ -37,28 +32,23 @@ func TestAccContentCreate(t *testing.T) {
3732
3833func TestAccContentUpdate (t * testing.T ) {
3934 var content Content
40- personalContentId := os .Getenv ("SUMOLOGIC_PF" )
4135
4236 resource .Test (t , resource.TestCase {
4337 PreCheck : func () { testAccPreCheck (t ) },
4438 Providers : testAccProviders ,
45- CheckDestroy : testAccCheckContentDestroy ,
39+ CheckDestroy : testAccCheckContentDestroy ( content ) ,
4640 Steps : []resource.TestStep {
4741 {
48- Config : testAccSumologicContent (personalContentId , configJson ),
42+ Config : testAccSumologicContent (configJson ),
4943 Check : resource .ComposeTestCheckFunc (
5044 testAccCheckContentExists ("sumologic_content.test" , & content , t ),
5145 testAccCheckContentAttributes ("sumologic_content.test" ),
52- // testAccCheckContentConfig(&content),
53- resource .TestCheckResourceAttr ("sumologic_content.test" , "parent_id" , personalContentId ),
5446 ),
5547 }, {
56- Config : testAccSumologicContent (personalContentId , updateConfigJson ),
48+ Config : testAccSumologicContent (updateConfigJson ),
5749 Check : resource .ComposeTestCheckFunc (
5850 testAccCheckContentExists ("sumologic_content.test" , & content , t ),
5951 testAccCheckContentAttributes ("sumologic_content.test" ),
60- // testAccCheckContentConfig(&content),
61- resource .TestCheckResourceAttr ("sumologic_content.test" , "parent_id" , personalContentId ),
6252 ),
6353 },
6454 },
@@ -90,7 +80,6 @@ func testAccCheckContentExists(name string, content *Content, t *testing.T) reso
9080func testAccCheckContentAttributes (name string ) resource.TestCheckFunc {
9181 return func (s * terraform.State ) error {
9282 f := resource .ComposeTestCheckFunc (
93- // resource.TestCheckResourceAttrSet(name, "config"),
9483 resource .TestCheckResourceAttrSet (name , "parent_id" ),
9584 )
9685 return f (s )
@@ -111,22 +100,15 @@ func testAccCheckContentConfig(content *Content) resource.TestCheckFunc {
111100 }
112101}
113102
114- func testAccCheckContentDestroy (s * terraform.State ) error {
115- client := testAccProvider .Meta ().(* Client )
116- for _ , r := range s .RootModule ().Resources {
117- id := r .Primary .ID
118- log .Printf ("Checking if ID is Destroyed: %s" , id )
119- c , err := client .GetContent (id )
120-
121- if err != nil {
122- return fmt .Errorf ("Encountered an error: " + err .Error ())
123- }
124-
125- if c != nil {
103+ func testAccCheckContentDestroy (content Content ) resource.TestCheckFunc {
104+ return func (s * terraform.State ) error {
105+ client := testAccProvider .Meta ().(* Client )
106+ _ , err := client .GetContent (content .ID )
107+ if err == nil {
126108 return fmt .Errorf ("Content still exists" )
127109 }
110+ return nil
128111 }
129- return nil
130112}
131113
132114var updateConfigJson = `{
@@ -211,13 +193,14 @@ var configJson = `{
211193 "description": "Runs every hour with timerange of 15m and sends email notifications"
212194}`
213195
214- func testAccSumologicContent (parentId string , configJson string ) string {
196+ func testAccSumologicContent (configJson string ) string {
215197 return fmt .Sprintf (`
198+ data "sumologic_personal_folder" "personalFolder" {}
216199resource "sumologic_content" "test" {
217- parent_id = "%s "
200+ parent_id = "${data.sumologic_personal_folder.personalFolder.id} "
218201 config = <<JSON
219202%s
220203JSON
221204}
222- ` , parentId , configJson )
205+ ` , configJson )
223206}
0 commit comments