Skip to content

Commit 273c1e7

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

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

sysdig/resource_sysdig_ip_filter_test.go

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

55
import (
66
"fmt"
7-
"github.com/draios/terraform-provider-sysdig/sysdig"
7+
"math/rand"
88
"testing"
9+
"time"
10+
11+
"github.com/draios/terraform-provider-sysdig/sysdig"
912

1013
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1114
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1215
)
1316

1417
func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
18+
ipRange1 := generateRandomIPRange()
19+
ipRange2 := generateRandomIPRange()
20+
1521
resource.Test(t, resource.TestCase{
1622
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv),
1723
ProviderFactories: map[string]func() (*schema.Provider, error){
@@ -21,19 +27,19 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
2127
},
2228
Steps: []resource.TestStep{
2329
{
24-
// Create resource
25-
Config: createIPFilter("192.168.1.0/24", "Initial note", true),
30+
// Create resource with the first random IP range
31+
Config: createIPFilter(ipRange1, "Initial note", true),
2632
Check: resource.ComposeTestCheckFunc(
27-
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.1.0/24"),
33+
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange1),
2834
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Initial note"),
2935
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "true"),
3036
),
3137
},
3238
{
33-
// Update resource
34-
Config: createIPFilter("192.168.2.0/24", "Updated note", false),
39+
// Update resource with the second random IP range
40+
Config: createIPFilter(ipRange2, "Updated note", false),
3541
Check: resource.ComposeTestCheckFunc(
36-
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.2.0/24"),
42+
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange2),
3743
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Updated note"),
3844
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "false"),
3945
),
@@ -42,6 +48,11 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
4248
})
4349
}
4450

51+
func generateRandomIPRange() string {
52+
rand.Seed(time.Now().UnixNano())
53+
return fmt.Sprintf("%d.%d.%d.0/24", rand.Intn(256), rand.Intn(256), rand.Intn(256))
54+
}
55+
4556
func createIPFilter(ipRange, note string, enabled bool) string {
4657
return fmt.Sprintf(`
4758
resource "sysdig_ip_filter" "test" {

0 commit comments

Comments
 (0)