Begin writing tests

This commit is contained in:
Ben Claussen 2019-12-10 15:10:02 -05:00
parent 8194acb5eb
commit 002feadb4a
4 changed files with 89 additions and 1 deletions

View file

@ -39,7 +39,7 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-DCIM_Support_ps1" ExportFunctions="False">Functions\DCIM\DCIM.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-IPAM_Support_ps1" ExportFunctions="False">Functions\IPAM\IPAM.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Virtualization_Support_ps1" ExportFunctions="False">Functions\Virtualization\Virtualization.Support.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-Setup_Support_ps1" ExportFunctions="False">Functions\Setup.Support.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Setup_Support_ps1" ExportFunctions="False">Functions\Setup.Support.ps1</File>
</Files>
<StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript>
</Project>

View file

@ -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'

View file

@ -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 {

View file

@ -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'