Skip to content

Commit

Permalink
chore(tests): improve custom field names in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fbreckle committed Mar 19, 2024
1 parent a71abb2 commit 59e1ca0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
49 changes: 46 additions & 3 deletions netbox/resource_netbox_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ resource "netbox_prefix" "test" {
{
Config: testAccNetboxPrefixFullDependencies(testName, randomSlug, testVid) + fmt.Sprintf(`
resource "netbox_custom_field" "test" {
name = "test"
name = "%s"
type = "text"
weight = 100
content_types = ["ipam.prefix"]
Expand All @@ -249,9 +249,52 @@ resource "netbox_prefix" "test" {
custom_fields = {
"${netbox_custom_field.test.name}" = "test-field"
}
}`, testPrefix, testDesc),
}`, testSlug, testPrefix, testDesc),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_prefix.test", fmt.Sprintf("custom_fields.%s", testSlug), "test-field"),
),
},
{
ResourceName: "netbox_prefix.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccNetboxPrefix_customFields(t *testing.T) {
testPrefix := "1.1.2.128/25"
testSlug := "prefix_cf"
testVid := "124"
randomSlug := testAccGetTestName(testSlug)
testDesc := "test prefix 2"
testName := testAccGetTestName(testSlug)
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNetboxPrefixFullDependencies(testName, randomSlug, testVid) + fmt.Sprintf(`
resource "netbox_custom_field" "test" {
name = "%s"
type = "text"
weight = 100
content_types = ["ipam.prefix"]
}
resource "netbox_prefix" "test" {
prefix = "%s"
description = "%s 2"
status = "active"
tags = [netbox_tag.test.name]
mark_utilized = true
custom_fields = {
"${netbox_custom_field.test.name}" = "test-field"
}
}`, testSlug, testPrefix, testDesc),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_prefix.test", "custom_fields.test", "test-field"),
resource.TestCheckResourceAttr("netbox_prefix.test", fmt.Sprintf("custom_fields.%s", testSlug), "test-field"),
),
},
{
Expand Down
6 changes: 3 additions & 3 deletions netbox/resource_netbox_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAccNetboxService_customFields(t *testing.T) {
{
Config: testAccNetboxServiceFullDependencies(testName) + fmt.Sprintf(`
resource "netbox_custom_field" "test" {
name = "custom_field"
name = "%s"
type = "text"
content_types = ["ipam.service"]
}
Expand All @@ -86,14 +86,14 @@ resource "netbox_service" "test_customfield" {
ports = [333]
protocol = "tcp"
custom_fields = {"${netbox_custom_field.test.name}" = "testtext"}
}`, testName),
}`, testSlug, testName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_service.test_customfield", "name", testName),
resource.TestCheckResourceAttrPair("netbox_service.test_customfield", "virtual_machine_id", "netbox_virtual_machine.test", "id"),
resource.TestCheckResourceAttr("netbox_service.test_customfield", "ports.#", "1"),
resource.TestCheckResourceAttr("netbox_service.test_customfield", "ports.0", "333"),
resource.TestCheckResourceAttr("netbox_service.test_customfield", "protocol", "tcp"),
resource.TestCheckResourceAttr("netbox_service.test_customfield", "custom_fields.custom_field", "testtext"),
resource.TestCheckResourceAttr("netbox_service.test_customfield", fmt.Sprintf("custom_fields.%s", testSlug), "testtext"),
),
},
{
Expand Down
8 changes: 4 additions & 4 deletions netbox/resource_netbox_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,18 @@ func TestAccNetboxVirtualMachine_customFields(t *testing.T) {
{
Config: testAccNetboxVirtualMachineFullDependencies(testName) + fmt.Sprintf(`
resource "netbox_custom_field" "test" {
name = "custom_field"
name = "%s"
type = "text"
content_types = ["virtualization.virtualmachine"]
}
resource "netbox_virtual_machine" "test" {
name = "%[1]s"
name = "%s"
cluster_id = netbox_cluster.test.id
site_id = netbox_site.test.id
custom_fields = {"${netbox_custom_field.test.name}" = "76"}
}`, testName),
}`, testSlug, testName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "custom_fields.custom_field", "76"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", fmt.Sprintf("custom_fields.%s", testSlug), "76"),
),
},
},
Expand Down

0 comments on commit 59e1ca0

Please sign in to comment.