Skip to content

Commit c10f866

Browse files
author
Sean Sain
committed
Fix Content create and update test failures
1 parent 95d803e commit c10f866

File tree

3 files changed

+24
-91
lines changed

3 files changed

+24
-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: 18 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,101 +111,28 @@ 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

124-
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-
}
132+
var updateConfigJson = `{"type":"SavedSearchWithScheduleSyncDefinition","name":"test-333","search":{"queryText":"\"warn\"","defaultTimeRange":"-15m","byReceiptTime":false,"viewName":"","viewStartTime":"1970-01-01T00:00:00Z","queryParameters":[],"parsingMode":"Manual"},"searchSchedule":{"cronExpression":"0 0 * * * ? *","displayableTimeRange":"-10m","parseableTimeRange":{"type":"BeginBoundedTimeRange","from":{"type":"RelativeTimeRangeBoundary","relativeTime":"-50m"},"to":null},"timeZone":"America/Los_Angeles","threshold":null,"notification":{"taskType":"EmailSearchNotificationSyncDefinition","toList":["[email protected]"],"subjectTemplate":"Search Results: {{SearchName}}","includeQuery":true,"includeResultSet":true,"includeHistogram":false,"includeCsvAttachment":false},"scheduleType":"1Hour","muteErrorEmails":false,"parameters":[]},"description":"Runs every hour with timerange of 15m and sends email notifications"}
165133
`
166134

167-
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-
}
135+
var configJson = `{"type":"SavedSearchWithScheduleSyncDefinition","name":"test-121","search":{"queryText":"\"error\"","defaultTimeRange":"-15m","byReceiptTime":false,"viewName":"","viewStartTime":"1970-01-01T00:00:00Z","queryParameters":[],"parsingMode":"Manual"},"searchSchedule":{"cronExpression":"0 0 * * * ? *","displayableTimeRange":"-10m","parseableTimeRange":{"type":"BeginBoundedTimeRange","from":{"type":"RelativeTimeRangeBoundary","relativeTime":"-50m"},"to":null},"timeZone":"America/Los_Angeles","threshold":null,"notification":{"taskType":"EmailSearchNotificationSyncDefinition","toList":["[email protected]"],"subjectTemplate":"Search Results: {{SearchName}}","includeQuery":true,"includeResultSet":true,"includeHistogram":false,"includeCsvAttachment":false},"scheduleType":"1Hour","muteErrorEmails":false,"parameters":[]},"description":"Runs every hour with timerange of 15m and sends email notifications"}
208136
`
209137

210138
func testAccSumologicContent(parentId string, configJson string) string {

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)