Skip to content

Commit

Permalink
revert the changes for cidr and added IPV6 test case for network cont…
Browse files Browse the repository at this point in the history
…ainer
  • Loading branch information
Chaithra001 committed Oct 24, 2024
1 parent ea225d2 commit 9df9d4b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
8 changes: 4 additions & 4 deletions infoblox/resource_infoblox_ip_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package infoblox

import (
"fmt"
"github.com/infobloxopen/infoblox-go-client/v2/utils"
"sort"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
ibclient "github.com/infobloxopen/infoblox-go-client/v2"
"github.com/infobloxopen/infoblox-go-client/v2/utils"
"regexp"
"sort"
"testing"
)

type v4addrsType []ibclient.HostRecordIpv4Addr
Expand Down
82 changes: 70 additions & 12 deletions infoblox/resource_infoblox_network_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,20 @@ func validateNetworkContainer(
nc.Comment, expComment)
}

filterparams := res.Primary.Attributes["filter_params"]
expCidr := expectedValue.Cidr
if len(filterparams) == 0 {
//cidr is not passed in nextavailable network container test case
//cidr is not passed in nextavailable network container test case
if expCidr == "" {
expCidr = res.Primary.Attributes["cidr"]
if expCidr == "" {
expCidr = res.Primary.Attributes["cidr"]
if expCidr == "" {
return fmt.Errorf(
"the value of 'cidr' field is empty, but expected some value")
}
}
if nc.Cidr != expCidr {
return fmt.Errorf(
"the value of 'cidr' field is '%s', but expected '%s'",
nc.Cidr, expCidr)
"the value of 'cidr' field is empty, but expected some value")
}
}
if nc.Cidr != expCidr {
return fmt.Errorf(
"the value of 'cidr' field is '%s', but expected '%s'",
nc.Cidr, expCidr)
}

// the rest is about extensible attributes
expectedEAs := expectedValue.Ea
Expand Down Expand Up @@ -614,6 +611,67 @@ func TestAcc_resourceNetworkContainer_AllocateNetworkByEA_IPV4(t *testing.T) {
})
}

var testResourceIPv6NetworkContainer = `resource "infoblox_ipv6_network_container" "ipv6_network12" {
cidr = "002:1f93:0:2::/96"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Darjeeling"
})
}
resource "infoblox_ipv6_network_container" "ipv6_network13"{
allocate_prefix_len = 97
comment = "network container created"
filter_params = jsonencode({
"*Site" = "Darjeeling"
})
ext_attrs = jsonencode({
Site = "Europe"
})
depends_on = [infoblox_ipv6_network_container.ipv6_network12]
}`

func TestAcc_resourceNetworkContainer_AllocateNetworkByEA_IPV6(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testResourceIPv6NetworkContainer,
Check: resource.ComposeTestCheckFunc(
validateNetworkContainer(
"infoblox_ipv6_network_container.ipv6_network13",
&ibclient.NetworkContainer{
NetviewName: "default",
Comment: "network container created",
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
// Negative testcase
Config: `
resource "infoblox_ipv6_network_container" "ipv6_network14"{
network_view="default"
comment = "network created"
allocate_prefix_len = 97
filter_params = jsonencode({
"*Site" = "Finland"
})
ext_attrs = jsonencode({
Site = "Europe"
})
}`,
ExpectError: regexp.MustCompile("did not return any result"),
},
},
})
}

func TestAcc_resourceNetworkContainer_ipv6(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down

0 comments on commit 9df9d4b

Please sign in to comment.