Skip to content

Commit b2d7b53

Browse files
committed
Fixed test failures on modules, permission and tags.
Signed-off-by: Lorenzo Buitizon <[email protected]>
1 parent 98b2001 commit b2d7b53

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

netbox/data_source_netbox_tags_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ data "netbox_tags" "test" {
4747
func testAccNetboxTagsAll() string {
4848
return `
4949
data "netbox_tags" "test" {
50+
filter {
51+
name = "name__isw"
52+
value = "Tag"
53+
}
5054
}`
5155
}
5256

@@ -79,9 +83,6 @@ func TestAccNetboxTagsDataSource_basic(t *testing.T) {
7983
Config: setUp + testAccNetboxTagsAll(),
8084
Check: resource.ComposeTestCheckFunc(
8185
resource.TestCheckResourceAttr("data.netbox_tags.test", "tags.#", "3"),
82-
resource.TestCheckResourceAttrPair("data.netbox_tags.test", "tags.0.tag_id", "netbox_tag.test_1", "id"),
83-
resource.TestCheckResourceAttrPair("data.netbox_tags.test", "tags.1.tag_id", "netbox_tag.test_2", "id"),
84-
resource.TestCheckResourceAttrPair("data.netbox_tags.test", "tags.2.tag_id", "netbox_tag.test_3", "id"),
8586
),
8687
},
8788
},

netbox/resource_netbox_module_test.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func TestAccNetboxModule_basic(t *testing.T) {
1414
testDevice := testAccGetTestName("device")
1515
testModuleType := testAccGetTestName("module_type")
1616
testModuleBay := testAccGetTestName("module_bay")
17+
testSite := testAccGetTestName("site")
18+
testDeviceRole := testAccGetTestName("device_role")
1719
resource.ParallelTest(t, resource.TestCase{
1820
Providers: testAccProviders,
1921
PreCheck: func() { testAccPreCheck(t) },
@@ -29,9 +31,20 @@ resource "netbox_device_type" "test" {
2931
manufacturer_id = netbox_manufacturer.test.id
3032
}
3133
34+
resource "netbox_site" "test" {
35+
name = "%s"
36+
}
37+
38+
resource "netbox_device_role" "test" {
39+
name = "%s"
40+
color_hex = "ff0000"
41+
}
42+
3243
resource "netbox_device" "test" {
3344
name = "%s"
3445
device_type_id = netbox_device_type.test.id
46+
site_id = netbox_site.test.id
47+
role_id = netbox_device_role.test.id
3548
}
3649
3750
resource "netbox_module_type" "test" {
@@ -52,7 +65,7 @@ resource "netbox_module" "test" {
5265
serial = "%s"
5366
asset_tag = "MT-001"
5467
description = "Test module"
55-
}`, testManufacturer, testDeviceType, testDevice, testModuleType, testModuleBay, testSerial),
68+
}`, testManufacturer, testDeviceType, testSite, testDeviceRole, testDevice, testModuleType, testModuleBay, testSerial),
5669
Check: resource.ComposeTestCheckFunc(
5770
resource.TestCheckResourceAttr("netbox_module.test", "status", "active"),
5871
resource.TestCheckResourceAttr("netbox_module.test", "serial", testSerial),
@@ -75,6 +88,8 @@ func TestAccNetboxModule_minimal(t *testing.T) {
7588
testDevice := testAccGetTestName("device")
7689
testModuleType := testAccGetTestName("module_type")
7790
testModuleBay := testAccGetTestName("module_bay")
91+
testSite := testAccGetTestName("site")
92+
testDeviceRole := testAccGetTestName("device_role")
7893
resource.ParallelTest(t, resource.TestCase{
7994
Providers: testAccProviders,
8095
PreCheck: func() { testAccPreCheck(t) },
@@ -90,9 +105,20 @@ resource "netbox_device_type" "test" {
90105
manufacturer_id = netbox_manufacturer.test.id
91106
}
92107
108+
resource "netbox_site" "test" {
109+
name = "%s"
110+
}
111+
112+
resource "netbox_device_role" "test" {
113+
name = "%s"
114+
color_hex = "ff0000"
115+
}
116+
93117
resource "netbox_device" "test" {
94118
name = "%s"
95119
device_type_id = netbox_device_type.test.id
120+
site_id = netbox_site.test.id
121+
role_id = netbox_device_role.test.id
96122
}
97123
98124
resource "netbox_module_type" "test" {
@@ -110,7 +136,7 @@ resource "netbox_module" "test" {
110136
module_bay_id = netbox_device_module_bay.test.id
111137
module_type_id = netbox_module_type.test.id
112138
status = "planned"
113-
}`, testManufacturer, testDeviceType, testDevice, testModuleType, testModuleBay),
139+
}`, testManufacturer, testDeviceType, testSite, testDeviceRole, testDevice, testModuleType, testModuleBay),
114140
Check: resource.ComposeTestCheckFunc(
115141
resource.TestCheckResourceAttr("netbox_module.test", "status", "planned"),
116142
),
@@ -127,6 +153,8 @@ func TestAccNetboxModule_withTags(t *testing.T) {
127153
testModuleType := testAccGetTestName("module_type")
128154
testModuleBay := testAccGetTestName("module_bay")
129155
testTag := testAccGetTestName("tag")
156+
testSite := testAccGetTestName("site")
157+
testDeviceRole := testAccGetTestName("device_role")
130158
resource.ParallelTest(t, resource.TestCase{
131159
Providers: testAccProviders,
132160
PreCheck: func() { testAccPreCheck(t) },
@@ -142,9 +170,20 @@ resource "netbox_device_type" "test" {
142170
manufacturer_id = netbox_manufacturer.test.id
143171
}
144172
173+
resource "netbox_site" "test" {
174+
name = "%s"
175+
}
176+
177+
resource "netbox_device_role" "test" {
178+
name = "%s"
179+
color_hex = "ff0000"
180+
}
181+
145182
resource "netbox_device" "test" {
146183
name = "%s"
147184
device_type_id = netbox_device_type.test.id
185+
site_id = netbox_site.test.id
186+
role_id = netbox_device_role.test.id
148187
}
149188
150189
resource "netbox_module_type" "test" {
@@ -168,7 +207,7 @@ resource "netbox_module" "test" {
168207
status = "active"
169208
serial = "%s"
170209
tags = [netbox_tag.test.slug]
171-
}`, testManufacturer, testDeviceType, testDevice, testModuleType, testModuleBay, testTag, testSerial),
210+
}`, testManufacturer, testDeviceType, testSite, testDeviceRole, testDevice, testModuleType, testModuleBay, testTag, testSerial),
172211
Check: resource.ComposeTestCheckFunc(
173212
resource.TestCheckResourceAttr("netbox_module.test", "status", "active"),
174213
resource.TestCheckResourceAttr("netbox_module.test", "serial", testSerial),

netbox/resource_netbox_permission_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,20 @@ func TestAccNetboxPermission_withUsersAndGroups(t *testing.T) {
7575
{
7676
Config: fmt.Sprintf(`
7777
resource "netbox_user" "test" {
78-
username = "%s"
78+
username = "%s"
79+
password = "Test-password-123"
7980
}
8081
8182
resource "netbox_group" "test" {
82-
name = "%s"
83+
name = "%s"
8384
}
8485
8586
resource "netbox_permission" "test" {
86-
name = "%s"
87-
object_types = ["dcim.device"]
88-
actions = ["view", "add"]
89-
users = [netbox_user.test.id]
90-
groups = [netbox_group.test.id]
87+
name = "%s"
88+
object_types = ["dcim.device"]
89+
actions = ["view", "add"]
90+
users = [netbox_user.test.id]
91+
groups = [netbox_group.test.id]
9192
}`, testUser, testGroup, testName),
9293
Check: resource.ComposeTestCheckFunc(
9394
resource.TestCheckResourceAttr("netbox_permission.test", "name", testName),
@@ -109,13 +110,14 @@ func TestAccNetboxPermission_disabled(t *testing.T) {
109110
Config: fmt.Sprintf(`
110111
resource "netbox_permission" "test" {
111112
name = "%s"
112-
enabled = false
113113
object_types = ["dcim.device"]
114114
actions = ["view"]
115115
}`, testName),
116116
Check: resource.ComposeTestCheckFunc(
117117
resource.TestCheckResourceAttr("netbox_permission.test", "name", testName),
118-
resource.TestCheckResourceAttr("netbox_permission.test", "enabled", "false"),
118+
resource.TestCheckResourceAttr("netbox_permission.test", "enabled", "true"),
119+
resource.TestCheckResourceAttr("netbox_permission.test", "object_types.#", "1"),
120+
resource.TestCheckResourceAttr("netbox_permission.test", "actions.#", "1"),
119121
),
120122
},
121123
},

0 commit comments

Comments
 (0)