diff --git a/NetboxPS.psproj b/NetboxPS.psproj index 1b008af..e938937 100644 --- a/NetboxPS.psproj +++ b/NetboxPS.psproj @@ -39,7 +39,7 @@ Functions\DCIM\DCIM.Support.ps1 Functions\IPAM\IPAM.Support.ps1 Functions\Virtualization\Virtualization.Support.ps1 - Functions\Setup.Support.ps1 + Functions\Setup.Support.ps1 R:\Netbox\NetboxPS\Test-Module.ps1 \ No newline at end of file diff --git a/Tests/IPAM.Tests.ps1 b/Tests/IPAM.Tests.ps1 index e637f75..73fa4f4 100644 --- a/Tests/IPAM.Tests.ps1 +++ b/Tests/IPAM.Tests.ps1 @@ -348,6 +348,41 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { } } + Context -Name "New-NetboxIPAMPrefix" -Fixture { + It "Should create a basic prefix" { + $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" + + Assert-VerifiableMock + + $Result.Method | Should -Be 'POST' + $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' + $Result.Headers.Keys.Count | Should -BeExactly 1 + $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1}' + } + + It "Should create a prefix with a status and role names" { + $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' + + Assert-VerifiableMock + + $Result.Method | Should -Be 'POST' + $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' + $Result.Headers.Keys.Count | Should -BeExactly 1 + $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"role":"Active"}' + } + + It "Should create a prefix with a status, role name, and tenant ID" { + $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' -Tenant 15 + + Assert-VerifiableMock + + $Result.Method | Should -Be 'POST' + $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' + $Result.Headers.Keys.Count | Should -BeExactly 1 + $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"tenant":15,"role":"Active"}' + } + } + Context -Name "New-NetboxIPAMAddress" -Fixture { It "Should create a basic IP address" { $Result = New-NetboxIPAMAddress -Address '10.0.0.1/24' diff --git a/dist/Tests/Helpers.Tests.ps1 b/dist/Tests/Helpers.Tests.ps1 index 63587eb..26ea592 100644 --- a/dist/Tests/Helpers.Tests.ps1 +++ b/dist/Tests/Helpers.Tests.ps1 @@ -146,6 +146,24 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture { $URIComponents.Parameters | Should -BeOfType [hashtable] $URIComponents.Parameters['q'] | Should -Be 'mytestquery' } + + It "Should generate custom field parameters" { + $URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{ + 'CustomFields' = @{ + 'PRTG_Id' = 1234 + 'Customer_Id' = 'abc' + } + } + + $URIComponents | Should -BeOfType [hashtable] + $URIComponents.Keys.Count | Should -BeExactly 2 + $URIComponents.Keys | Should -Be @("Segments", "Parameters") + $URIComponents.Segments | Should -Be @("segment1", "segment2") + $URIComponents.Parameters.Count | Should -BeExactly 2 + $URIComponents.Parameters | Should -BeOfType [hashtable] + $URIComponents.Parameters['cf_prtg_id'] | Should -Be '1234' + $URIComponents.Parameters['cf_customer_id'] | Should -Be 'abc' + } } Context -Name "Invoking request tests" -Fixture { diff --git a/dist/Tests/IPAM.Tests.ps1 b/dist/Tests/IPAM.Tests.ps1 index e637f75..73fa4f4 100644 --- a/dist/Tests/IPAM.Tests.ps1 +++ b/dist/Tests/IPAM.Tests.ps1 @@ -348,6 +348,41 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture { } } + Context -Name "New-NetboxIPAMPrefix" -Fixture { + It "Should create a basic prefix" { + $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" + + Assert-VerifiableMock + + $Result.Method | Should -Be 'POST' + $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' + $Result.Headers.Keys.Count | Should -BeExactly 1 + $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1}' + } + + It "Should create a prefix with a status and role names" { + $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' + + Assert-VerifiableMock + + $Result.Method | Should -Be 'POST' + $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' + $Result.Headers.Keys.Count | Should -BeExactly 1 + $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"role":"Active"}' + } + + It "Should create a prefix with a status, role name, and tenant ID" { + $Result = New-NetboxIPAMPrefix -Prefix "10.0.0.0/24" -Status 'Active' -Role 'Active' -Tenant 15 + + Assert-VerifiableMock + + $Result.Method | Should -Be 'POST' + $Result.URI | Should -Be 'https://netbox.domain.com/api/ipam/prefixes/' + $Result.Headers.Keys.Count | Should -BeExactly 1 + $Result.Body | Should -Be '{"prefix":"10.0.0.0/24","status":1,"tenant":15,"role":"Active"}' + } + } + Context -Name "New-NetboxIPAMAddress" -Fixture { It "Should create a basic IP address" { $Result = New-NetboxIPAMAddress -Address '10.0.0.1/24'