Skip to content

Commit

Permalink
fix ip_filter acc test - delete resource after creation to avoid conf…
Browse files Browse the repository at this point in the history
…lict during next run
  • Loading branch information
vojindj committed Sep 16, 2024
1 parent de61a83 commit 4d39d54
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions sysdig/resource_sysdig_ip_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ package sysdig_test

import (
"fmt"
"github.com/draios/terraform-provider-sysdig/sysdig"
"testing"

"github.com/draios/terraform-provider-sysdig/sysdig"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
ipRange1 := generateRandomIPRange()
ipRange2 := generateRandomIPRange()

resource.Test(t, resource.TestCase{
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv),
ProviderFactories: map[string]func() (*schema.Provider, error){
Expand All @@ -21,19 +25,19 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
},
Steps: []resource.TestStep{
{
// Create resource
Config: createIPFilter("192.168.1.0/24", "Initial note", true),
// Create resource with the first random IP range
Config: createIPFilter(ipRange1, "Initial note", true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.1.0/24"),
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange1),
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Initial note"),
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "true"),
),
},
{
// Update resource
Config: createIPFilter("192.168.2.0/24", "Updated note", false),
// Update resource with the second random IP range
Config: createIPFilter(ipRange2, "Updated note", false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.2.0/24"),
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange2),
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Updated note"),
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "false"),
),
Expand All @@ -42,6 +46,11 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
})
}

func generateRandomIPRange() string {
rand.Seed(time.Now().UnixNano())

Check failure on line 50 in sysdig/resource_sysdig_ip_filter_test.go

View workflow job for this annotation

GitHub Actions / Test / Sysdig Secure Acceptance Tests

undefined: rand

Check failure on line 50 in sysdig/resource_sysdig_ip_filter_test.go

View workflow job for this annotation

GitHub Actions / Test / Sysdig Secure Acceptance Tests

undefined: time

Check failure on line 50 in sysdig/resource_sysdig_ip_filter_test.go

View workflow job for this annotation

GitHub Actions / Test / Sysdig Monitor Acceptance Tests

undefined: rand

Check failure on line 50 in sysdig/resource_sysdig_ip_filter_test.go

View workflow job for this annotation

GitHub Actions / Test / Sysdig Monitor Acceptance Tests

undefined: time
return fmt.Sprintf("%d.%d.%d.0/24", rand.Intn(256), rand.Intn(256), rand.Intn(256))

Check failure on line 51 in sysdig/resource_sysdig_ip_filter_test.go

View workflow job for this annotation

GitHub Actions / Test / Sysdig Secure Acceptance Tests

undefined: rand

Check failure on line 51 in sysdig/resource_sysdig_ip_filter_test.go

View workflow job for this annotation

GitHub Actions / Test / Sysdig Monitor Acceptance Tests

undefined: rand
}

func createIPFilter(ipRange, note string, enabled bool) string {
return fmt.Sprintf(`
resource "sysdig_ip_filter" "test" {
Expand Down

0 comments on commit 4d39d54

Please sign in to comment.