Skip to content

Commit 2b44117

Browse files
Fix acceptance tests
1 parent ce7a18e commit 2b44117

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

sumologic/resource_sumologic_scan_budget_test.go

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func TestAccSumologicScanBudget_basic(t *testing.T) {
3232
testApplicableOn := "PerEntity"
3333
testGroupBy := "User"
3434
testAction := "StopForeGroundScan"
35+
testScope := ScanBudgetScope{
36+
IncludedUsers: []string{"000000000000011C"},
37+
ExcludedUsers: []string{},
38+
IncludedRoles: []string{},
39+
ExcludedRoles: []string{"0000000000000196"},
40+
}
3541
testStatus := "active"
3642

3743
resource.Test(t, resource.TestCase{
@@ -40,7 +46,7 @@ func TestAccSumologicScanBudget_basic(t *testing.T) {
4046
CheckDestroy: testAccCheckScanBudgetDestroy(scanBudget),
4147
Steps: []resource.TestStep{
4248
{
43-
Config: testAccCheckSumologicScanBudgetConfigImported(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testStatus),
49+
Config: testAccCheckSumologicScanBudgetConfigImported(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testScope, testStatus),
4450
},
4551
{
4652
ResourceName: "sumologic_scan_budget.foo",
@@ -61,6 +67,12 @@ func TestAccSumologicScanBudget_create(t *testing.T) {
6167
testApplicableOn := "PerEntity"
6268
testGroupBy := "User"
6369
testAction := "StopForeGroundScan"
70+
testScope := ScanBudgetScope{
71+
IncludedUsers: []string{"000000000000011C"},
72+
ExcludedUsers: []string{},
73+
IncludedRoles: []string{},
74+
ExcludedRoles: []string{"0000000000000196"},
75+
}
6476
testStatus := "active"
6577

6678
resource.Test(t, resource.TestCase{
@@ -69,7 +81,7 @@ func TestAccSumologicScanBudget_create(t *testing.T) {
6981
CheckDestroy: testAccCheckScanBudgetDestroy(scanBudget),
7082
Steps: []resource.TestStep{
7183
{
72-
Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testStatus),
84+
Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testScope, testStatus),
7385
Check: resource.ComposeTestCheckFunc(
7486
testAccCheckScanBudgetExists("sumologic_scan_budget.test", &scanBudget, t),
7587
testAccCheckScanBudgetAttributes("sumologic_scan_budget.test"),
@@ -99,6 +111,12 @@ func TestAccSumologicScanBudget_update(t *testing.T) {
99111
testApplicableOn := "PerEntity"
100112
testGroupBy := "User"
101113
testAction := "StopForeGroundScan"
114+
testScope := ScanBudgetScope{
115+
IncludedUsers: []string{"000000000000011C"},
116+
ExcludedUsers: []string{},
117+
IncludedRoles: []string{},
118+
ExcludedRoles: []string{"0000000000000196"},
119+
}
102120
testStatus := "active"
103121

104122
testUpdatedName := "Test Budget"
@@ -109,6 +127,12 @@ func TestAccSumologicScanBudget_update(t *testing.T) {
109127
testUpdatedApplicableOn := "PerEntity"
110128
testUpdatedGroupBy := "User"
111129
testUpdatedAction := "Warn"
130+
testUpdatedScope := ScanBudgetScope{
131+
IncludedUsers: []string{"000000000000011C"},
132+
ExcludedUsers: []string{},
133+
IncludedRoles: []string{},
134+
ExcludedRoles: []string{"0000000000000196"},
135+
}
112136
testUpdatedStatus := "active"
113137

114138
resource.Test(t, resource.TestCase{
@@ -117,7 +141,7 @@ func TestAccSumologicScanBudget_update(t *testing.T) {
117141
CheckDestroy: testAccCheckScanBudgetDestroy(scanBudget),
118142
Steps: []resource.TestStep{
119143
{
120-
Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testStatus),
144+
Config: testAccSumologicScanBudget(testName, testCapacity, testUnit, testBudgetType, testWindow, testApplicableOn, testGroupBy, testAction, testScope, testStatus),
121145
Check: resource.ComposeTestCheckFunc(
122146
testAccCheckScanBudgetExists("sumologic_scan_budget.test", &scanBudget, t),
123147
testAccCheckScanBudgetAttributes("sumologic_scan_budget.test"),
@@ -133,7 +157,7 @@ func TestAccSumologicScanBudget_update(t *testing.T) {
133157
),
134158
},
135159
{
136-
Config: testAccSumologicScanBudgetUpdate(testUpdatedName, testUpdatedCapacity, testUpdatedUnit, testUpdatedBudgetType, testUpdatedWindow, testUpdatedApplicableOn, testUpdatedGroupBy, testUpdatedAction, testUpdatedStatus),
160+
Config: testAccSumologicScanBudgetUpdate(testUpdatedName, testUpdatedCapacity, testUpdatedUnit, testUpdatedBudgetType, testUpdatedWindow, testUpdatedApplicableOn, testUpdatedGroupBy, testUpdatedAction, testUpdatedScope, testUpdatedStatus),
137161
Check: resource.ComposeTestCheckFunc(
138162
resource.TestCheckResourceAttr("sumologic_scan_budget.test", "name", testUpdatedName),
139163
resource.TestCheckResourceAttr("sumologic_scan_budget.test", "capacity", strconv.Itoa(testUpdatedCapacity)),
@@ -155,11 +179,8 @@ func testAccCheckScanBudgetDestroy(scanBudget ScanBudget) resource.TestCheckFunc
155179
client := testAccProvider.Meta().(*Client)
156180
for _, r := range s.RootModule().Resources {
157181
id := r.Primary.ID
158-
u, err := client.GetScanBudget(id)
159-
if err != nil {
160-
return fmt.Errorf("Encountered an error: " + err.Error())
161-
}
162-
if u != nil {
182+
_, err := client.GetScanBudget(id)
183+
if err == nil {
163184
return fmt.Errorf("ScanBudget %s still exists", id)
164185
}
165186
}
@@ -190,7 +211,7 @@ func testAccCheckScanBudgetExists(name string, scanBudget *ScanBudget, t *testin
190211
return nil
191212
}
192213
}
193-
func testAccCheckSumologicScanBudgetConfigImported(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, status string) string {
214+
func testAccCheckSumologicScanBudgetConfigImported(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, scope ScanBudgetScope, status string) string {
194215
return fmt.Sprintf(`
195216
resource "sumologic_scan_budget" "foo" {
196217
name = "%s"
@@ -202,17 +223,17 @@ resource "sumologic_scan_budget" "foo" {
202223
group_by = "%s"
203224
action = "%s"
204225
scope {
205-
included_users = ["000000000000011C"]
226+
included_users = ["%s"]
206227
excluded_users = []
207228
included_roles = []
208-
excluded_roles = ["0000000000000196"]
229+
excluded_roles = ["%s"]
209230
}
210231
status = "%s"
211232
}
212-
`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, status)
233+
`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, scope.IncludedUsers[0], scope.ExcludedRoles[0], status)
213234
}
214235

215-
func testAccSumologicScanBudget(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, status string) string {
236+
func testAccSumologicScanBudget(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, scope ScanBudgetScope, status string) string {
216237
return fmt.Sprintf(`
217238
resource "sumologic_scan_budget" "test" {
218239
name = "%s"
@@ -224,17 +245,17 @@ resource "sumologic_scan_budget" "test" {
224245
group_by = "%s"
225246
action = "%s"
226247
scope {
227-
included_users = ["000000000000011C"]
248+
included_users = ["%s"]
228249
excluded_users = []
229250
included_roles = []
230-
excluded_roles = ["0000000000000196"]
251+
excluded_roles = ["%s"]
231252
}
232253
status = "%s"
233254
}
234-
`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, status)
255+
`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, scope.IncludedUsers[0], scope.ExcludedRoles[0], status)
235256
}
236257

237-
func testAccSumologicScanBudgetUpdate(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, status string) string {
258+
func testAccSumologicScanBudgetUpdate(name string, capacity int, unit string, budgetType string, window string, applicableOn string, groupBy string, action string, scope ScanBudgetScope, status string) string {
238259
return fmt.Sprintf(`
239260
resource "sumologic_scan_budget" "test" {
240261
name = "%s"
@@ -246,14 +267,14 @@ resource "sumologic_scan_budget" "test" {
246267
group_by = "%s"
247268
action = "%s"
248269
scope {
249-
included_users = ["000000000000011C"]
270+
included_users = ["%s"]
250271
excluded_users = []
251272
included_roles = []
252-
excluded_roles = ["0000000000000196"]
273+
excluded_roles = ["%s"]
253274
}
254275
status = "%s"
255276
}
256-
`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, status)
277+
`, name, capacity, unit, budgetType, window, applicableOn, groupBy, action, scope.IncludedUsers[0], scope.ExcludedRoles[0], status)
257278
}
258279

259280
func testAccCheckScanBudgetAttributes(name string) resource.TestCheckFunc {

0 commit comments

Comments
 (0)