Skip to content

Commit 4d39d54

Browse files
committed
fix ip_filter acc test - delete resource after creation to avoid conflict during next run
1 parent de61a83 commit 4d39d54

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

sysdig/resource_sysdig_ip_filter_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ package sysdig_test
44

55
import (
66
"fmt"
7-
"github.com/draios/terraform-provider-sysdig/sysdig"
87
"testing"
98

9+
"github.com/draios/terraform-provider-sysdig/sysdig"
10+
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1213
)
1314

1415
func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
16+
ipRange1 := generateRandomIPRange()
17+
ipRange2 := generateRandomIPRange()
18+
1519
resource.Test(t, resource.TestCase{
1620
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv),
1721
ProviderFactories: map[string]func() (*schema.Provider, error){
@@ -21,19 +25,19 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
2125
},
2226
Steps: []resource.TestStep{
2327
{
24-
// Create resource
25-
Config: createIPFilter("192.168.1.0/24", "Initial note", true),
28+
// Create resource with the first random IP range
29+
Config: createIPFilter(ipRange1, "Initial note", true),
2630
Check: resource.ComposeTestCheckFunc(
27-
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.1.0/24"),
31+
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange1),
2832
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Initial note"),
2933
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "true"),
3034
),
3135
},
3236
{
33-
// Update resource
34-
Config: createIPFilter("192.168.2.0/24", "Updated note", false),
37+
// Update resource with the second random IP range
38+
Config: createIPFilter(ipRange2, "Updated note", false),
3539
Check: resource.ComposeTestCheckFunc(
36-
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.2.0/24"),
40+
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange2),
3741
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Updated note"),
3842
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "false"),
3943
),
@@ -42,6 +46,11 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
4246
})
4347
}
4448

49+
func generateRandomIPRange() string {
50+
rand.Seed(time.Now().UnixNano())
51+
return fmt.Sprintf("%d.%d.%d.0/24", rand.Intn(256), rand.Intn(256), rand.Intn(256))
52+
}
53+
4554
func createIPFilter(ipRange, note string, enabled bool) string {
4655
return fmt.Sprintf(`
4756
resource "sysdig_ip_filter" "test" {

0 commit comments

Comments
 (0)