Skip to content

Commit 74a4a5d

Browse files
committed
INVS-1420 test 51
1 parent 6c7ff3b commit 74a4a5d

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

sumologic/resource_sumologic_cse_match_list.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ func resourceSumologicCSEMatchList() *schema.Resource {
121121
Computed: true,
122122
},
123123
"items": {
124-
Type: schema.TypeList,
125-
Optional: true,
126-
DiffSuppressFunc: MatchListItemsDiffSuppressFunc,
124+
Type: schema.TypeSet,
125+
Optional: true,
126+
//DiffSuppressFunc: MatchListItemsDiffSuppressFunc,
127127
Elem: &schema.Resource{
128128
Schema: map[string]*schema.Schema{
129129
"id": {
@@ -239,12 +239,12 @@ func resourceSumologicCSEMatchListCreate(d *schema.ResourceData, meta interface{
239239
d.SetId(id)
240240

241241
//Match list items
242-
itemsData := d.Get("items").([]interface{})
242+
//itemsData := d.Get("items").([]interface{})
243+
itemsData := d.Get("items").(*schema.Set).List()
243244
var items []CSEMatchListItemPost
244245
for _, data := range itemsData {
245246
item, _ := resourceToCSEMatchListItem([]interface{}{data})
246247
items = append(items, item)
247-
248248
}
249249

250250
if len(items) > 0 {
@@ -299,6 +299,7 @@ func resourceToCSEMatchListItem(data interface{}) (CSEMatchListItemPost, string)
299299
}
300300

301301
func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{}) error {
302+
println("in update")
302303
CSEMatchListPost, err := resourceToCSEMatchList(d)
303304
if err != nil {
304305
return err
@@ -310,17 +311,19 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
310311
}
311312

312313
//Match list items
313-
itemsData := d.Get("items").([]interface{})
314+
//itemsData := d.Get("items").([]interface{})
315+
itemsData := d.Get("items").(*schema.Set).List()
314316
var itemIds []string
315317
var items []CSEMatchListItemPost
316318
for _, data := range itemsData {
317319
item, id := resourceToCSEMatchListItem([]interface{}{data})
318320
item.ID = ""
319321
items = append(items, item)
320322
itemIds = append(itemIds, id)
321-
322323
}
323324

325+
println(itemIds)
326+
324327
if len(items) > 0 {
325328
err2 := c.CreateCSEMatchListItems(items, d.Id())
326329
if err2 != nil {
@@ -337,6 +340,8 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
337340
}
338341
if CSEMatchListItems != nil {
339342

343+
println("343")
344+
340345
for _, t := range CSEMatchListItems.CSEMatchListItemsGetObjects {
341346
if !contains(itemIds, t.ID) {
342347
err3 := c.DeleteCSEMatchListItem(t.ID)
@@ -347,6 +352,8 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
347352
}
348353
}
349354

355+
println("355")
356+
350357
createStateConf := &resource.StateChangeConf{
351358
Target: []string{
352359
fmt.Sprint(len(items)),
@@ -365,6 +372,9 @@ func resourceSumologicCSEMatchListUpdate(d *schema.ResourceData, meta interface{
365372
}
366373

367374
_, err = createStateConf.WaitForState()
375+
376+
println("376")
377+
368378
if err != nil {
369379
return fmt.Errorf("error waiting for match list (%s) to be updated: %s", d.Id(), err)
370380
}

sumologic/resource_sumologic_cse_match_list_test.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/google/uuid"
8+
79
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
810
"github.com/hashicorp/terraform-plugin-sdk/terraform"
911
)
@@ -14,14 +16,14 @@ func TestAccSumologicSCEMatchList_createAndUpdate(t *testing.T) {
1416
var matchList CSEMatchListGet
1517
nDefaultTtl := 10800
1618
nDescription := "New Match List Description"
17-
nName := "Match List Name"
19+
nName := fmt.Sprintf("Match List Name %s", uuid.New())
1820
nTargetColumn := "SrcIp"
1921
liDescription := "Match List Item Description"
2022
liValue := "value"
2123
liExpiration := "2122-02-27T04:00:00"
22-
// uDefaultTtl := 3600
23-
// uDescription := "Updated Match List Description"
24-
// uliDescription := "Updated Match List item Description"
24+
uDefaultTtl := 3600
25+
uDescription := "Updated Match List Description"
26+
uliDescription := "Updated Match List item Description"
2527
resourceName := "sumologic_cse_match_list.match_list"
2628

2729
resource.Test(t, resource.TestCase{
@@ -30,26 +32,26 @@ func TestAccSumologicSCEMatchList_createAndUpdate(t *testing.T) {
3032
CheckDestroy: testAccCSEMatchListDestroy,
3133
Steps: []resource.TestStep{
3234
{
33-
Config: testCreateCSEMatchListConfig(nDefaultTtl, nDescription, nName, nTargetColumn, liDescription, liExpiration, liValue, 11),
35+
Config: testCreateCSEMatchListConfig(nDefaultTtl, nDescription, nName, nTargetColumn, liDescription, liExpiration, liValue, 51),
3436
Check: resource.ComposeTestCheckFunc(
3537
testCheckCSEMatchListExists(resourceName, &matchList),
3638
testCheckMatchListValues(&matchList, nDefaultTtl, nDescription, nName, nTargetColumn),
3739
resource.TestCheckResourceAttrSet(resourceName, "id"),
3840
),
3941
},
40-
// {
41-
// Config: testCreateCSEMatchListConfig(uDefaultTtl, uDescription, nName, nTargetColumn, uliDescription, liExpiration, liValue, 11),
42-
// Check: resource.ComposeTestCheckFunc(
43-
// testCheckCSEMatchListExists(resourceName, &matchList),
44-
// testCheckMatchListValues(&matchList, uDefaultTtl, uDescription, nName, nTargetColumn),
45-
// ),
46-
// },
47-
// {
48-
// Config: testDeleteCSEMatchListItemConfig(uDefaultTtl, uDescription, nName, nTargetColumn),
49-
// Check: resource.ComposeTestCheckFunc(
50-
// testCheckMatchListItemsEmpty(resourceName),
51-
// ),
52-
// },
42+
{
43+
Config: testCreateCSEMatchListConfig(uDefaultTtl, uDescription, nName, nTargetColumn, uliDescription, liExpiration, liValue, 51),
44+
Check: resource.ComposeTestCheckFunc(
45+
testCheckCSEMatchListExists(resourceName, &matchList),
46+
testCheckMatchListValues(&matchList, uDefaultTtl, uDescription, nName, nTargetColumn),
47+
),
48+
},
49+
{
50+
Config: testDeleteCSEMatchListItemConfig(uDefaultTtl, uDescription, nName, nTargetColumn),
51+
Check: resource.ComposeTestCheckFunc(
52+
testCheckMatchListItemsEmpty(resourceName),
53+
),
54+
},
5355
},
5456
})
5557
}
@@ -81,12 +83,14 @@ func testCreateCSEMatchListConfig(nDefaultTtl int, nDescription string, nName st
8183
var itemsStr = ""
8284

8385
for i := 0; i < numItems; i++ {
86+
id := uuid.New()
87+
8488
itemsStr += fmt.Sprintf(`
8589
items {
8690
description = "%s %d"
8791
expiration = "%s"
88-
value = "%s %d"
89-
}`, liDescription, i, liExpiration, liValue, i)
92+
value = "%s %d %s"
93+
}`, liDescription, i, liExpiration, liValue, i, id)
9094
}
9195

9296
var str = fmt.Sprintf(`

sumologic/sumologic_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
219219
_, etag, _ := s.Get(sumoURL.String())
220220

221221
body, _ := json.Marshal(payload)
222+
223+
println(string(body))
224+
222225
req, err := createNewRequest(http.MethodPut, sumoURL.String(), bytes.NewBuffer(body), s.AccessID, s.AccessKey, s.AuthJwt)
223226
if err != nil {
224227
return nil, err

0 commit comments

Comments
 (0)