Skip to content

Commit 6737433

Browse files
author
Sean Sain
committed
remove SUMOLOGIC_PF by adding the datasource to the tests
1 parent 55dbd93 commit 6737433

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

sumologic/provider_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,4 @@ func testAccPreCheck(t *testing.T) {
3838
if v := os.Getenv("SUMOLOGIC_ENVIRONMENT"); v == "" {
3939
t.Fatal("SUMOLOGIC_ENVIRONMENT must be set for acceptance tests")
4040
}
41-
if v := os.Getenv("SUMOLOGIC_PF"); v == "" {
42-
t.Fatal("SUMOLOGIC_PF must be set for acceptance tests")
43-
}
4441
}

sumologic/resource_sumologic_content_test.go

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package sumologic
33
import (
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
1614
func 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

3833
func 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
9080
func 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

132114
var 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" {}
216199
resource "sumologic_content" "test" {
217-
parent_id = "%s"
200+
parent_id = "${data.sumologic_personal_folder.personalFolder.id}"
218201
config = <<JSON
219202
%s
220203
JSON
221204
}
222-
`, parentId, configJson)
205+
`, configJson)
223206
}

sumologic/resource_sumologic_folder_test.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sumologic
22

33
import (
44
"fmt"
5-
"os"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
@@ -13,21 +12,19 @@ import (
1312
func TestAccFolderCreate(t *testing.T) {
1413
var folder Folder
1514
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
16-
personalFolderId := os.Getenv("SUMOLOGIC_PF")
1715

1816
resource.Test(t, resource.TestCase{
1917
PreCheck: func() { testAccPreCheck(t) },
2018
Providers: testAccProviders,
2119
CheckDestroy: testAccCheckFolderDestroy(folder),
2220
Steps: []resource.TestStep{
2321
{
24-
Config: testAccSumologicFolder(rName, personalFolderId),
22+
Config: testAccSumologicFolder(rName),
2523
Check: resource.ComposeTestCheckFunc(
2624
testAccCheckFolderExists("sumologic_folder.test", &folder, t),
2725
testAccCheckFolderAttributes("sumologic_folder.test"),
2826
resource.TestCheckResourceAttr("sumologic_folder.test", "description", "test"),
2927
resource.TestCheckResourceAttr("sumologic_folder.test", "name", rName),
30-
resource.TestCheckResourceAttr("sumologic_folder.test", "parent_id", personalFolderId),
3128
),
3229
},
3330
},
@@ -37,31 +34,28 @@ func TestAccFolderCreate(t *testing.T) {
3734
func TestAccFolderUpdate(t *testing.T) {
3835
var folder Folder
3936
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
40-
personalFolderId := os.Getenv("SUMOLOGIC_PF")
4137

4238
resource.Test(t, resource.TestCase{
4339
PreCheck: func() { testAccPreCheck(t) },
4440
Providers: testAccProviders,
4541
CheckDestroy: testAccCheckFolderDestroy(folder),
4642
Steps: []resource.TestStep{
4743
{
48-
Config: testAccSumologicFolder(rName, personalFolderId),
44+
Config: testAccSumologicFolder(rName),
4945
Check: resource.ComposeTestCheckFunc(
5046
testAccCheckFolderExists("sumologic_folder.test", &folder, t),
5147
testAccCheckFolderAttributes("sumologic_folder.test"),
5248
resource.TestCheckResourceAttr("sumologic_folder.test", "description", "test"),
5349
resource.TestCheckResourceAttr("sumologic_folder.test", "name", rName),
54-
resource.TestCheckResourceAttr("sumologic_folder.test", "parent_id", personalFolderId),
5550
),
5651
},
5752
{
58-
Config: testAccSumologicFolderUpdate(rName, personalFolderId),
53+
Config: testAccSumologicFolderUpdate(rName),
5954
Check: resource.ComposeTestCheckFunc(
6055
testAccCheckFolderExists("sumologic_folder.test", &folder, t),
6156
testAccCheckFolderAttributes("sumologic_folder.test"),
6257
resource.TestCheckResourceAttr("sumologic_folder.test", "description", "Update test"),
6358
resource.TestCheckResourceAttr("sumologic_folder.test", "name", rName),
64-
resource.TestCheckResourceAttr("sumologic_folder.test", "parent_id", personalFolderId),
6559
),
6660
},
6761
},
@@ -112,22 +106,24 @@ func testAccCheckFolderDestroy(folder Folder) resource.TestCheckFunc {
112106
}
113107
}
114108

115-
func testAccSumologicFolder(name string, parentId string) string {
109+
func testAccSumologicFolder(name string) string {
116110
return fmt.Sprintf(`
111+
data "sumologic_personal_folder" "personalFolder" {}
117112
resource "sumologic_folder" "test" {
118113
name = "%s"
119-
parent_id = "%s"
114+
parent_id = "${data.sumologic_personal_folder.personalFolder.id}"
120115
description = "test"
121116
}
122-
`, name, parentId)
117+
`, name)
123118
}
124119

125-
func testAccSumologicFolderUpdate(name string, parentId string) string {
120+
func testAccSumologicFolderUpdate(name string) string {
126121
return fmt.Sprintf(`
122+
data "sumologic_personal_folder" "personalFolder" {}
127123
resource "sumologic_folder" "test" {
128124
name = "%s"
129-
parent_id = "%s"
125+
parent_id = "${data.sumologic_personal_folder.personalFolder.id}"
130126
description = "Update test"
131127
}
132-
`, name, parentId)
128+
`, name)
133129
}

0 commit comments

Comments
 (0)