Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,19 @@ 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/acctest"
"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 +26,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 +47,10 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
})
}

func generateRandomIPRange() string {
return fmt.Sprintf("%d.%d.%d.0/24", acctest.RandIntRange(0, 255), acctest.RandIntRange(0, 255), acctest.RandIntRange(0, 255))
}

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