@@ -2,8 +2,6 @@ package sumologic
22
33import (
44 "fmt"
5- "log"
6- "os"
75 "testing"
86
97 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -13,20 +11,17 @@ import (
1311//Testing create functionality for Content resources
1412func TestAccContent_create (t * testing.T ) {
1513 var content Content
16- personalContentId := os .Getenv ("SUMOLOGIC_PF" )
1714
1815 resource .Test (t , resource.TestCase {
1916 PreCheck : func () { testAccPreCheck (t ) },
2017 Providers : testAccProviders ,
21- CheckDestroy : testAccCheckContentDestroy ,
18+ CheckDestroy : testAccCheckContentDestroy ( content ) ,
2219 Steps : []resource.TestStep {
2320 {
24- Config : testAccSumologicContent (personalContentId , configJson ),
21+ Config : testAccSumologicContent (configJson ),
2522 Check : resource .ComposeTestCheckFunc (
2623 testAccCheckContentExists ("sumologic_content.test" , & content , t ),
2724 testAccCheckContentAttributes ("sumologic_content.test" ),
28- // testAccCheckContentConfig(&content),
29- resource .TestCheckResourceAttr ("sumologic_content.test" , "parent_id" , personalContentId ),
3025 ),
3126 },
3227 },
@@ -35,28 +30,23 @@ func TestAccContent_create(t *testing.T) {
3530
3631func TestAccContent_update (t * testing.T ) {
3732 var content Content
38- personalContentId := os .Getenv ("SUMOLOGIC_PF" )
3933
4034 resource .Test (t , resource.TestCase {
4135 PreCheck : func () { testAccPreCheck (t ) },
4236 Providers : testAccProviders ,
43- CheckDestroy : testAccCheckContentDestroy ,
37+ CheckDestroy : testAccCheckContentDestroy ( content ) ,
4438 Steps : []resource.TestStep {
4539 {
46- Config : testAccSumologicContent (personalContentId , configJson ),
40+ Config : testAccSumologicContent (configJson ),
4741 Check : resource .ComposeTestCheckFunc (
4842 testAccCheckContentExists ("sumologic_content.test" , & content , t ),
4943 testAccCheckContentAttributes ("sumologic_content.test" ),
50- // testAccCheckContentConfig(&content),
51- resource .TestCheckResourceAttr ("sumologic_content.test" , "parent_id" , personalContentId ),
5244 ),
5345 }, {
54- Config : testAccSumologicContent (personalContentId , updateConfigJson ),
46+ Config : testAccSumologicContent (updateConfigJson ),
5547 Check : resource .ComposeTestCheckFunc (
5648 testAccCheckContentExists ("sumologic_content.test" , & content , t ),
5749 testAccCheckContentAttributes ("sumologic_content.test" ),
58- // testAccCheckContentConfig(&content),
59- resource .TestCheckResourceAttr ("sumologic_content.test" , "parent_id" , personalContentId ),
6050 ),
6151 },
6252 },
@@ -88,29 +78,21 @@ func testAccCheckContentExists(name string, content *Content, t *testing.T) reso
8878func testAccCheckContentAttributes (name string ) resource.TestCheckFunc {
8979 return func (s * terraform.State ) error {
9080 f := resource .ComposeTestCheckFunc (
91- // resource.TestCheckResourceAttrSet(name, "config"),
9281 resource .TestCheckResourceAttrSet (name , "parent_id" ),
9382 )
9483 return f (s )
9584 }
9685}
9786
98- func testAccCheckContentDestroy (s * terraform.State ) error {
99- client := testAccProvider .Meta ().(* Client )
100- for _ , r := range s .RootModule ().Resources {
101- id := r .Primary .ID
102- log .Printf ("Checking if ID is Destroyed: %s" , id )
103- c , err := client .GetContent (id )
104-
105- if err != nil {
106- return fmt .Errorf ("Encountered an error: " + err .Error ())
107- }
108-
109- if c != nil {
87+ func testAccCheckContentDestroy (content Content ) resource.TestCheckFunc {
88+ return func (s * terraform.State ) error {
89+ client := testAccProvider .Meta ().(* Client )
90+ _ , err := client .GetContent (content .ID )
91+ if err == nil {
11092 return fmt .Errorf ("Content still exists" )
11193 }
94+ return nil
11295 }
113- return nil
11496}
11597
11698var updateConfigJson = `{
@@ -195,13 +177,14 @@ var configJson = `{
195177 "description": "Runs every hour with timerange of 15m and sends email notifications"
196178}`
197179
198- func testAccSumologicContent (parentId string , configJson string ) string {
180+ func testAccSumologicContent (configJson string ) string {
199181 return fmt .Sprintf (`
182+ data "sumologic_personal_folder" "personalFolder" {}
200183resource "sumologic_content" "test" {
201- parent_id = "%s "
184+ parent_id = "${data.sumologic_personal_folder.personalFolder.id} "
202185 config = <<JSON
203186%s
204187JSON
205188}
206- ` , parentId , configJson )
189+ ` , configJson )
207190}
0 commit comments