Skip to content

Commit

Permalink
test cases for host record and network container for next available IP
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaithra001 committed Oct 23, 2024
1 parent d8fc7f9 commit 281af3f
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 10 deletions.
167 changes: 167 additions & 0 deletions infoblox/resource_infoblox_ip_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,170 @@ func testAccCheckIPAllocationDestroy(s *terraform.State) error {
}
return nil
}

var testResourceIPAllocationIPV4 = `resource "infoblox_ipv4_network" "ipv4_network12" {
cidr = "189.11.0.0/24"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Darjeeling"
})
}
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "ipv4"{
fqdn = "testhostnameip5.test.com"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Darjeeling"
})
ext_attrs = jsonencode({
Site = "Europe"
})
ip_address_type="IPV4"
depends_on = [infoblox_ipv4_network.ipv4_network12,infoblox_zone_auth.zone]
}`
var testResourceIPAllocationIPV6 = `resource "infoblox_ipv6_network" "ipv6_network12" {
cidr = "2002:1f93:0:4::/96"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Bengaluru"
})
}
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "ipv6"{
fqdn = "testhostnameip6.test.com"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Bengaluru"
})
ext_attrs = jsonencode({
Site = "Europe"
})
ip_address_type="IPV6"
depends_on = [infoblox_ipv6_network.ipv6_network12,infoblox_zone_auth.zone]
}`
var testResourceIPAllocationIPV6IPV4 = `resource "infoblox_ipv6_network" "ipv6_network12" {
cidr = "2002:1f93:0:4::/96"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Bengaluru"
})
}
resource "infoblox_ipv4_network" "ipv4_network12" {
cidr = "189.11.0.0/24"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Bengaluru"
})
}
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "both"{
fqdn = "testhostnameip7.test.com"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Bengaluru"
})
ext_attrs = jsonencode({
Site = "Europe"
})
ip_address_type="Both"
depends_on = [infoblox_ipv6_network.ipv6_network12,infoblox_zone_auth.zone,infoblox_ipv4_network.ipv4_network12]
}`

func TestAcc_resourceNetwork_AllocateNetworkByEA_IPV4_IP_Allocation(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testResourceIPAllocationIPV4,
Check: resource.ComposeTestCheckFunc(
validateIPAllocation(
"infoblox_ip_allocation.ipv4",
&ibclient.HostRecord{
NetworkView: "default",
View: utils.StringPtr("default"),
EnableDns: utils.BoolPtr(true),
Name: utils.StringPtr("testhostnameip5.test.com"),
Ipv4Addrs: []ibclient.HostRecordIpv4Addr{*ibclient.NewHostRecordIpv4Addr("189.11.0.1", "", false, "")},
UseTtl: utils.BoolPtr(false),
Comment: utils.StringPtr("host record created"),
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
Config: testResourceIPAllocationIPV6,
Check: resource.ComposeTestCheckFunc(
validateIPAllocation(
"infoblox_ip_allocation.ipv6",
&ibclient.HostRecord{
NetworkView: "default",
View: utils.StringPtr("default"),
EnableDns: utils.BoolPtr(true),
Name: utils.StringPtr("testhostnameip6.test.com"),
Ipv6Addrs: []ibclient.HostRecordIpv6Addr{*ibclient.NewHostRecordIpv6Addr("2002:1f93:0:4::1", "", false, "")},
UseTtl: utils.BoolPtr(false),
Comment: utils.StringPtr("host record created"),
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
Config: testResourceIPAllocationIPV6IPV4,
Check: resource.ComposeTestCheckFunc(
validateIPAllocation(
"infoblox_ip_allocation.both",
&ibclient.HostRecord{
NetworkView: "default",
View: utils.StringPtr("default"),
EnableDns: utils.BoolPtr(true),
Name: utils.StringPtr("testhostnameip7.test.com"),
Ipv4Addrs: []ibclient.HostRecordIpv4Addr{*ibclient.NewHostRecordIpv4Addr("189.11.0.1", "", false, "")},
Ipv6Addrs: []ibclient.HostRecordIpv6Addr{*ibclient.NewHostRecordIpv6Addr("2002:1f93:0:4::1", "", false, "")},
UseTtl: utils.BoolPtr(false),
Comment: utils.StringPtr("host record created"),
Ea: ibclient.EA{
"Site": "Europe",
},
},
)),
},
{
// Negative testcase
Config: `
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "ipv4_1"{
fqdn = "testhostnameip6.test.com"
network_view="default"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Finland"
})
ext_attrs = jsonencode({
Site = "Europe"
})
}`,
ExpectError: regexp.MustCompile("did not return any result"),
},
},
})
}
83 changes: 73 additions & 10 deletions infoblox/resource_infoblox_network_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,24 @@ func validateNetworkContainer(
nc.Comment, expComment)
}

filterparams := res.Primary.Attributes["filter_params"]
expCidr := expectedValue.Cidr
//cidr is not passed in nextavailable network container test case
if expCidr == "" {
expCidr = res.Primary.Attributes["cidr"]
if len(filterparams) == 0 {
//cidr is not passed in nextavailable network container test case
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 empty, but expected some value")
"the value of 'cidr' field is '%s', but expected '%s'",
nc.Cidr, expCidr)
}
}

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
if expectedEAs == nil && nc.Ea != nil {
Expand Down Expand Up @@ -551,6 +553,67 @@ func TestAcc_resourceNetworkContainer_ipv4_ea_inheritance(t *testing.T) {
})
}

var testResourceIPv4NetworkContainer = `resource "infoblox_ipv4_network_container" "ipv4_network12" {
cidr = "25.11.0.0/24"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Darjeeling"
})
}
resource "infoblox_ipv4_network_container" "ipv4_network13"{
allocate_prefix_len = 26
comment = "network container created"
filter_params = jsonencode({
"*Site" = "Darjeeling"
})
ext_attrs = jsonencode({
Site = "Europe"
})
depends_on = [infoblox_ipv4_network_container.ipv4_network12]
}`

func TestAcc_resourceNetworkContainer_AllocateNetworkByEA_IPV4(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testResourceIPv4NetworkContainer,
Check: resource.ComposeTestCheckFunc(
validateNetworkContainer(
"infoblox_ipv4_network_container.ipv4_network13",
&ibclient.NetworkContainer{
NetviewName: "default",
Comment: "network container created",
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
// Negative testcase
Config: `
resource "infoblox_ipv4_network_container" "ipv4_network14"{
network_view="default"
comment = "network created"
allocate_prefix_len = 26
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 281af3f

Please sign in to comment.