From 2eb56682b20a478ea12eb749906e05d2ca9cdfae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Nie=C3=9F?= Date: Mon, 1 May 2023 23:21:18 +0200 Subject: [PATCH] feat: Improve custom field tests to contain usage test --- ...netbox_extras_custom_field_boolean_test.go | 11 +++++++++++ ...ce_netbox_extras_custom_field_date_test.go | 11 +++++++++++ ...netbox_extras_custom_field_integer_test.go | 11 +++++++++++ ...ce_netbox_extras_custom_field_json_test.go | 19 +++++++++++++++++++ ...etbox_extras_custom_field_longtext_test.go | 11 +++++++++++ ...ox_extras_custom_field_multiobject_test.go | 17 +++++++++++++++++ ...ox_extras_custom_field_multiselect_test.go | 15 +++++++++++++++ ..._netbox_extras_custom_field_object_test.go | 13 +++++++++++++ ..._netbox_extras_custom_field_select_test.go | 11 +++++++++++ ...ce_netbox_extras_custom_field_text_test.go | 11 +++++++++++ ...rce_netbox_extras_custom_field_url_test.go | 11 +++++++++++ 11 files changed, 141 insertions(+) diff --git a/netbox/extras/resource_netbox_extras_custom_field_boolean_test.go b/netbox/extras/resource_netbox_extras_custom_field_boolean_test.go index 467bf8e34..c441480b5 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_boolean_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_boolean_test.go @@ -110,6 +110,17 @@ func testAccCheckNetboxExtrasCustomFieldBooleanConfig(nameSuffix string, resourc default = true {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = false + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_date_test.go b/netbox/extras/resource_netbox_extras_custom_field_date_test.go index 1c9bbcc1e..9e9980e35 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_date_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_date_test.go @@ -110,6 +110,17 @@ func testAccCheckNetboxExtrasCustomFieldDateConfig(nameSuffix string, resourceFu default = jsonencode("2022-01-01") {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = "2023-01-25" + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_integer_test.go b/netbox/extras/resource_netbox_extras_custom_field_integer_test.go index 85e7a5d6f..05bf54657 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_integer_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_integer_test.go @@ -112,6 +112,17 @@ func testAccCheckNetboxExtrasCustomFieldIntegerConfig(nameSuffix string, resourc validation_maximum = 500 {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = 25 + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_json_test.go b/netbox/extras/resource_netbox_extras_custom_field_json_test.go index 9e40f8738..0a35ebac6 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_json_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_json_test.go @@ -116,6 +116,25 @@ func testAccCheckNetboxExtrasCustomFieldJSONConfig(nameSuffix string, resourceFu }) {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = jsonencode( + { + mystring = "string" + mynumber = 6 + mydict = { + mybool = false + } + } + ) + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_longtext_test.go b/netbox/extras/resource_netbox_extras_custom_field_longtext_test.go index 51a63a973..3c099596d 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_longtext_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_longtext_test.go @@ -111,6 +111,17 @@ func testAccCheckNetboxExtrasCustomFieldLongtextConfig(nameSuffix string, resour validation_regex = "^.*$" {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = "My text" + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_multiobject_test.go b/netbox/extras/resource_netbox_extras_custom_field_multiobject_test.go index 231b9086c..82068ffe7 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_multiobject_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_multiobject_test.go @@ -120,6 +120,23 @@ func testAccCheckNetboxExtrasCustomFieldMultiObjectConfig(nameSuffix string, res ]) {{ end }} } + + {{ if eq .extraresources "true" }} + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = jsonencode( + [ + netbox_dcim_platform.test.id, + ] + ) + } + } + {{ end }} ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_multiselect_test.go b/netbox/extras/resource_netbox_extras_custom_field_multiselect_test.go index b20e8f99f..fe8a394da 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_multiselect_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_multiselect_test.go @@ -114,6 +114,21 @@ func testAccCheckNetboxExtrasCustomFieldMultiSelectConfig(nameSuffix string, res default = jsonencode(["test"]) {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = jsonencode( + [ + "test2", + ] + ) + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_object_test.go b/netbox/extras/resource_netbox_extras_custom_field_object_test.go index a69cb82ba..74fdd7de1 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_object_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_object_test.go @@ -120,6 +120,19 @@ func testAccCheckNetboxExtrasCustomFieldObjectConfig(nameSuffix string, resource ) {{ end }} } + + {{ if eq .extraresources "true" }} + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = netbox_dcim_platform.test.id + } + } + {{ end }} ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_select_test.go b/netbox/extras/resource_netbox_extras_custom_field_select_test.go index c39789d06..04140d669 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_select_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_select_test.go @@ -114,6 +114,17 @@ func testAccCheckNetboxExtrasCustomFieldSelectConfig(nameSuffix string, resource default = jsonencode("test") {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = "test2" + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_text_test.go b/netbox/extras/resource_netbox_extras_custom_field_text_test.go index b0daa1cf9..60aa4b9b9 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_text_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_text_test.go @@ -111,6 +111,17 @@ func testAccCheckNetboxExtrasCustomFieldTextConfig(nameSuffix string, resourceFu validation_regex = "^.*$" {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = "My text" + } + } ` data := map[string]string{ "namesuffix": nameSuffix, diff --git a/netbox/extras/resource_netbox_extras_custom_field_url_test.go b/netbox/extras/resource_netbox_extras_custom_field_url_test.go index 5ef50d748..de0371dd0 100644 --- a/netbox/extras/resource_netbox_extras_custom_field_url_test.go +++ b/netbox/extras/resource_netbox_extras_custom_field_url_test.go @@ -110,6 +110,17 @@ func testAccCheckNetboxExtrasCustomFieldURLConfig(nameSuffix string, resourceFul default = jsonencode("https://netbox.dev/") {{ end }} } + + resource "netbox_dcim_site" "test_assign" { + name = "test-a-{{ .namesuffix }}" + slug = "test-a-{{ .namesuffix }}" + + custom_field { + name = netbox_extras_custom_field.test.name + type = netbox_extras_custom_field.test.type + value = "http://my.example.url.invalid/path" + } + } ` data := map[string]string{ "namesuffix": nameSuffix,