@@ -2,6 +2,7 @@ package sumologic
22
33import (
44 "fmt"
5+ "strings"
56 "testing"
67
78 "github.com/google/uuid"
@@ -14,42 +15,52 @@ func TestAccSumologicSCEMatchList_createAndUpdate(t *testing.T) {
1415 SkipCseTest (t )
1516
1617 var matchList CSEMatchListGet
18+ resourceName := "sumologic_cse_match_list.match_list"
19+
20+ // Create values
21+ nName := fmt .Sprintf ("Terraform Test Match List %s" , uuid .New ())
1722 nDefaultTtl := 10800
18- nDescription := "New Match List Description"
19- nName := fmt .Sprintf ("Match List Name %s" , uuid .New ())
23+ nDescription := "Match List Description"
2024 nTargetColumn := "SrcIp"
2125 liDescription := "Match List Item Description"
22- liValue := "value"
2326 liExpiration := "2122-02-27T04:00:00"
27+ liValue := "value"
28+ liCount := 1001
29+
30+ // Update values
2431 uDefaultTtl := 3600
2532 uDescription := "Updated Match List Description"
2633 uliDescription := "Updated Match List item Description"
27- resourceName := "sumologic_cse_match_list.match_list"
34+ uliExpiration := "2122-02-27T05:00:00"
35+ uliValue := "updated value"
36+ uliCount := 1001
2837
2938 resource .Test (t , resource.TestCase {
3039 PreCheck : func () { testAccPreCheck (t ) },
3140 Providers : testAccProviders ,
3241 CheckDestroy : testAccCSEMatchListDestroy ,
3342 Steps : []resource.TestStep {
3443 {
35- Config : testCreateCSEMatchListConfig (nDefaultTtl , nDescription , nName , nTargetColumn , liDescription , liExpiration , liValue , 1000 ),
44+ Config : testCreateCSEMatchListConfig (nDefaultTtl , nDescription , nName , nTargetColumn , liDescription , liExpiration , liValue , liCount ),
3645 Check : resource .ComposeTestCheckFunc (
3746 testCheckCSEMatchListExists (resourceName , & matchList ),
3847 testCheckMatchListValues (& matchList , nDefaultTtl , nDescription , nName , nTargetColumn ),
48+ testCheckMatchListItemsValuesAndCount (resourceName , liDescription , liExpiration , liValue , liCount ),
3949 resource .TestCheckResourceAttrSet (resourceName , "id" ),
4050 ),
4151 },
4252 {
43- Config : testCreateCSEMatchListConfig (uDefaultTtl , uDescription , nName , nTargetColumn , uliDescription , liExpiration , liValue , 1000 ),
53+ Config : testCreateCSEMatchListConfig (uDefaultTtl , uDescription , nName , nTargetColumn , uliDescription , uliExpiration , uliValue , uliCount ),
4454 Check : resource .ComposeTestCheckFunc (
4555 testCheckCSEMatchListExists (resourceName , & matchList ),
4656 testCheckMatchListValues (& matchList , uDefaultTtl , uDescription , nName , nTargetColumn ),
57+ testCheckMatchListItemsValuesAndCount (resourceName , uliDescription , uliExpiration , uliValue , uliCount ),
4758 ),
4859 },
4960 {
5061 Config : testDeleteCSEMatchListItemConfig (uDefaultTtl , uDescription , nName , nTargetColumn ),
5162 Check : resource .ComposeTestCheckFunc (
52- testCheckMatchListItemsEmpty (resourceName ),
63+ testCheckMatchListItemsValuesAndCount (resourceName , "" , "" , "" , 0 ),
5364 ),
5465 },
5566 },
@@ -139,15 +150,34 @@ func testCheckCSEMatchListExists(n string, matchList *CSEMatchListGet) resource.
139150 }
140151}
141152
142- func testCheckMatchListItemsEmpty ( n string ) resource.TestCheckFunc {
153+ func testCheckMatchListValues ( matchList * CSEMatchListGet , nDefaultTtl int , nDescription string , nName string , nTargetColumn string ) resource.TestCheckFunc {
143154 return func (s * terraform.State ) error {
144- rs , ok := s .RootModule ().Resources [n ]
155+ if matchList .DefaultTtl != nDefaultTtl {
156+ return fmt .Errorf ("bad default ttl, expected \" %s\" , got: %#v" , nName , matchList .Name )
157+ }
158+ if matchList .Description != nDescription {
159+ return fmt .Errorf ("bad description, expected \" %s\" , got: %#v" , nDescription , matchList .Description )
160+ }
161+ if matchList .Name != nName {
162+ return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , nName , matchList .Name )
163+ }
164+ if matchList .TargetColumn != nTargetColumn {
165+ return fmt .Errorf ("bad target column, expected \" %s\" , got: %#v" , nName , matchList .Name )
166+ }
167+
168+ return nil
169+ }
170+ }
171+
172+ func testCheckMatchListItemsValuesAndCount (resourceName string , expectedDescription string , expectedExpiration string , expectedValue string , expectedCount int ) resource.TestCheckFunc {
173+ return func (s * terraform.State ) error {
174+ rs , ok := s .RootModule ().Resources [resourceName ]
145175 if ! ok {
146- return fmt .Errorf ("not found: %s" , n )
176+ return fmt .Errorf ("not found: %s" , resourceName )
147177 }
148178
149179 if rs .Primary .ID == "" {
150- return fmt .Errorf ("match List ID is not set " )
180+ return fmt .Errorf ("expected match list ID to be non-empty, but found empty string instead " )
151181 }
152182
153183 c := testAccProvider .Meta ().(* Client )
@@ -156,29 +186,29 @@ func testCheckMatchListItemsEmpty(n string) resource.TestCheckFunc {
156186 return err
157187 }
158188
159- if len (matchListResp .CSEMatchListItemsGetObjects ) != 0 {
160- return fmt .Errorf ("match list items not empty" )
189+ actualCount := len (matchListResp .CSEMatchListItemsGetObjects )
190+ if actualCount != expectedCount {
191+ return fmt .Errorf ("expected %d match list items, but found %d instead" , expectedCount , actualCount )
161192 }
162193
163- return nil
164- }
165- }
166-
167- func testCheckMatchListValues (matchList * CSEMatchListGet , nDefaultTtl int , nDescription string , nName string , nTargetColumn string ) resource.TestCheckFunc {
168- return func (s * terraform.State ) error {
169- if matchList .DefaultTtl != nDefaultTtl {
170- return fmt .Errorf ("bad default ttl, expected \" %s\" , got: %#v" , nName , matchList .Name )
171- }
172- if matchList .Description != nDescription {
173- return fmt .Errorf ("bad description, expected \" %s\" , got: %#v" , nDescription , matchList .Description )
174- }
175- if matchList .Name != nName {
176- return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , nName , matchList .Name )
177- }
178- if matchList .TargetColumn != nTargetColumn {
179- return fmt .Errorf ("bad target column, expected \" %s\" , got: %#v" , nName , matchList .Name )
194+ if expectedCount == 0 {
195+ return nil
180196 }
181197
198+ for _ , item := range matchListResp .CSEMatchListItemsGetObjects {
199+ if item .ID == "" {
200+ return fmt .Errorf ("expected match list item ID to be non-empty, but found empty string instead" )
201+ }
202+ if ! strings .Contains (item .Meta .Description , expectedDescription ) {
203+ return fmt .Errorf ("expected match list item description to contain \" %s\" , but found \" %s\" instead" , expectedDescription , item .Meta .Description )
204+ }
205+ if item .Expiration != expectedExpiration {
206+ return fmt .Errorf ("expected expiration to be \" %s\" , but found \" %s\" instead" , expectedExpiration , item .Expiration )
207+ }
208+ if ! strings .Contains (item .Value , expectedValue ) {
209+ return fmt .Errorf ("expected match list item value to contain \" %s\" , but found \" %s\" instead" , expectedValue , item .Value )
210+ }
211+ }
182212 return nil
183213 }
184214}
0 commit comments