From 6618afbbc87ac61bce1800b03ce8e6090de32d06 Mon Sep 17 00:00:00 2001 From: Xabier Napal Date: Tue, 24 Dec 2024 16:44:55 +0100 Subject: [PATCH] test: add tests for available_prefix resource custom fields support Signed-off-by: Xabier Napal --- .../resource_netbox_available_prefix_test.go | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/netbox/resource_netbox_available_prefix_test.go b/netbox/resource_netbox_available_prefix_test.go index fc673747..fae6e5c9 100644 --- a/netbox/resource_netbox_available_prefix_test.go +++ b/netbox/resource_netbox_available_prefix_test.go @@ -100,6 +100,50 @@ resource "netbox_available_prefix" "test" { }) } +func TestAccNetboxAvailablePrefix_cf(t *testing.T) { + testParentPrefix := "1.1.0.0/24" + testPrefixLength := 25 + expectedPrefix := "1.1.0.0/25" + testSlug := "prefix_cf" + testDesc := "test cf prefix" + testName := testAccGetTestName(testSlug) + + resourceName := "netbox_available_prefix.test" + + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccNetboxAvailablePrefixFullDependencies(testName, testParentPrefix) + fmt.Sprintf(` +resource "netbox_custom_field" "test" { + name = "%s" + type = "text" + weight = 100 + content_types = ["ipam.prefix"] +} + +resource "netbox_available_prefix" "test" { + parent_prefix_id = netbox_prefix.parent.id + prefix_length = %d + description = "%s" + status = "active" + tags = [netbox_tag.test.name] + mark_utilized = true + is_pool = true + + custom_fields = { + "${netbox_custom_field.test.name}" = "test-field" + } +}`, testSlug, testPrefixLength, testDesc), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "prefix", expectedPrefix), + //resource.TestCheckResourceAttr("netbox_available_prefix.test", fmt.Sprintf("custom_fields.%s", testSlug), "test-field"), + ), + }, + }, + }) +} + func TestAccNetboxAvailablePrefix_multiplePrefixesSerial(t *testing.T) { testParentPrefix := "1.1.0.0/24" testPrefixLength := 25