Skip to content

Commit 2ad5cf3

Browse files
authored
Merge pull request #101 from SumoLogic/ssain-fix-content-test-failures
Fix Content create and update test failures
2 parents 9450fcb + 8fb64bd commit 2ad5cf3

File tree

3 files changed

+100
-91
lines changed

3 files changed

+100
-91
lines changed

sumologic/resource_sumologic_content.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package sumologic
22

33
import (
44
"encoding/json"
5-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
65
"log"
76
"reflect"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
89
)
910

1011
func resourceSumologicContent() *schema.Resource {

sumologic/resource_sumologic_content_test.go

Lines changed: 94 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sumologic
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
67
"os"
78
"reflect"
89
"testing"
@@ -19,7 +20,7 @@ func TestAccContentCreate(t *testing.T) {
1920
resource.Test(t, resource.TestCase{
2021
PreCheck: func() { testAccPreCheck(t) },
2122
Providers: testAccProviders,
22-
CheckDestroy: testAccCheckContentDestroy(content),
23+
CheckDestroy: testAccCheckContentDestroy,
2324
Steps: []resource.TestStep{
2425
{
2526
Config: testAccSumologicContent(personalContentId, configJson),
@@ -41,7 +42,7 @@ func TestAccContentUpdate(t *testing.T) {
4142
resource.Test(t, resource.TestCase{
4243
PreCheck: func() { testAccPreCheck(t) },
4344
Providers: testAccProviders,
44-
CheckDestroy: testAccCheckContentDestroy(content),
45+
CheckDestroy: testAccCheckContentDestroy,
4546
Steps: []resource.TestStep{
4647
{
4748
Config: testAccSumologicContent(personalContentId, configJson),
@@ -110,102 +111,105 @@ func testAccCheckContentConfig(content *Content) resource.TestCheckFunc {
110111
}
111112
}
112113

113-
func testAccCheckContentDestroy(content Content) resource.TestCheckFunc {
114-
return func(s *terraform.State) error {
115-
client := testAccProvider.Meta().(*Client)
116-
_, err := client.GetContent(content.ID)
117-
if err == nil {
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 {
118126
return fmt.Errorf("Content still exists")
119127
}
120-
return nil
121128
}
129+
return nil
122130
}
123131

124132
var updateConfigJson = `{
125-
"type": "SavedSearchWithScheduleSyncDefinition",
126-
"name": "test-333",
127-
"search": {
128-
"queryText": "\"warn\"",
129-
"defaultTimeRange": "-15m",
130-
"byReceiptTime": false,
131-
"viewName": "",
132-
"viewStartTime": "1970-01-01T00:00:00Z",
133-
"queryParameters": []
134-
},
135-
"searchSchedule": {
136-
"cronExpression": "0 0 * * * ? *",
137-
"displayableTimeRange": "-10m",
138-
"parseableTimeRange": {
139-
"type": "BeginBoundedTimeRange",
140-
"from": {
141-
"type": "RelativeTimeRangeBoundary",
142-
"relativeTime": "-50m"
143-
},
144-
"to": null
145-
},
146-
"timeZone": "America/Los_Angeles",
147-
"threshold": null,
148-
"notification": {
149-
"taskType": "EmailSearchNotificationSyncDefinition",
150-
"toList": [
151-
152-
],
153-
"subjectTemplate": "Search Results: {{SearchName}}",
154-
"includeQuery": true,
155-
"includeResultSet": true,
156-
"includeHistogram": false,
157-
"includeCsvAttachment": false
158-
},
159-
"scheduleType": "1Hour",
160-
"muteErrorEmails": false,
161-
"parameters": []
162-
},
163-
"description": "Runs every hour with timerange of 15m and sends email notifications"
164-
}
165-
`
133+
"type": "SavedSearchWithScheduleSyncDefinition",
134+
"name": "test-333",
135+
"search": {
136+
"queryText": "\"warn\"",
137+
"defaultTimeRange": "-15m",
138+
"byReceiptTime": false,
139+
"viewName": "",
140+
"viewStartTime": "1970-01-01T00:00:00Z",
141+
"queryParameters": [],
142+
"parsingMode": "Manual"
143+
},
144+
"searchSchedule": {
145+
"cronExpression": "0 0 * * * ? *",
146+
"displayableTimeRange": "-10m",
147+
"parseableTimeRange": {
148+
"type": "BeginBoundedTimeRange",
149+
"from": {
150+
"type": "RelativeTimeRangeBoundary",
151+
"relativeTime": "-50m"
152+
},
153+
"to": null
154+
},
155+
"timeZone": "America/Los_Angeles",
156+
"threshold": null,
157+
"notification": {
158+
"taskType": "EmailSearchNotificationSyncDefinition",
159+
"toList": ["[email protected]"],
160+
"subjectTemplate": "Search Results: {{SearchName}}",
161+
"includeQuery": true,
162+
"includeResultSet": true,
163+
"includeHistogram": false,
164+
"includeCsvAttachment": false
165+
},
166+
"scheduleType": "1Hour",
167+
"muteErrorEmails": false,
168+
"parameters": []
169+
},
170+
"description": "Runs every hour with timerange of 15m and sends email notifications"
171+
}`
166172

167173
var configJson = `{
168-
"type": "SavedSearchWithScheduleSyncDefinition",
169-
"name": "test-121",
170-
"search": {
171-
"queryText": "\"error\"",
172-
"defaultTimeRange": "-15m",
173-
"byReceiptTime": false,
174-
"viewName": "",
175-
"viewStartTime": "1970-01-01T00:00:00Z",
176-
"queryParameters": []
177-
},
178-
"searchSchedule": {
179-
"cronExpression": "0 0 * * * ? *",
180-
"displayableTimeRange": "-10m",
181-
"parseableTimeRange": {
182-
"type": "BeginBoundedTimeRange",
183-
"from": {
184-
"type": "RelativeTimeRangeBoundary",
185-
"relativeTime": "-50m"
186-
},
187-
"to": null
188-
},
189-
"timeZone": "America/Los_Angeles",
190-
"threshold": null,
191-
"notification": {
192-
"taskType": "EmailSearchNotificationSyncDefinition",
193-
"toList": [
194-
195-
],
196-
"subjectTemplate": "Search Results: {{SearchName}}",
197-
"includeQuery": true,
198-
"includeResultSet": true,
199-
"includeHistogram": false,
200-
"includeCsvAttachment": false
201-
},
202-
"scheduleType": "1Hour",
203-
"muteErrorEmails": false,
204-
"parameters": []
205-
},
206-
"description": "Runs every hour with timerange of 15m and sends email notifications"
207-
}
208-
`
174+
"type": "SavedSearchWithScheduleSyncDefinition",
175+
"name": "test-121",
176+
"search": {
177+
"queryText": "\"error\"",
178+
"defaultTimeRange": "-15m",
179+
"byReceiptTime": false,
180+
"viewName": "",
181+
"viewStartTime": "1970-01-01T00:00:00Z",
182+
"queryParameters": [],
183+
"parsingMode": "Manual"
184+
},
185+
"searchSchedule": {
186+
"cronExpression": "0 0 * * * ? *",
187+
"displayableTimeRange": "-10m",
188+
"parseableTimeRange": {
189+
"type": "BeginBoundedTimeRange",
190+
"from": {
191+
"type": "RelativeTimeRangeBoundary",
192+
"relativeTime": "-50m"
193+
},
194+
"to": null
195+
},
196+
"timeZone": "America/Los_Angeles",
197+
"threshold": null,
198+
"notification": {
199+
"taskType": "EmailSearchNotificationSyncDefinition",
200+
"toList": ["[email protected]"],
201+
"subjectTemplate": "Search Results: {{SearchName}}",
202+
"includeQuery": true,
203+
"includeResultSet": true,
204+
"includeHistogram": false,
205+
"includeCsvAttachment": false
206+
},
207+
"scheduleType": "1Hour",
208+
"muteErrorEmails": false,
209+
"parameters": []
210+
},
211+
"description": "Runs every hour with timerange of 15m and sends email notifications"
212+
}`
209213

210214
func testAccSumologicContent(parentId string, configJson string) string {
211215
return fmt.Sprintf(`

sumologic/sumologic_content.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"log"
7+
"strings"
78
"time"
89
)
910

@@ -19,6 +20,9 @@ func (s *Client) GetContent(id string) (*Content, error) {
1920

2021
//If there was an error, exit here and return it
2122
if err != nil {
23+
if strings.Contains(err.Error(), "Content with the given ID does not exist.") {
24+
return nil, nil
25+
}
2226
return nil, err
2327
}
2428

0 commit comments

Comments
 (0)