mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 02:35:46 +00:00
Tests: Fix PSSA (#27)
* Tests: fix indent/align (with Visual Formatter Code) * Tests: Suppress warning about use ConvertToSecureString... * Setup(Tests): fix PSSA about unused variable
This commit is contained in:
parent
a608d6ebd7
commit
7edbae953f
7 changed files with 80 additions and 52 deletions
|
|
@ -11,6 +11,10 @@
|
||||||
DCIM tests.
|
DCIM tests.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -28,12 +32,12 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture {
|
||||||
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
||||||
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
||||||
return [ordered]@{
|
return [ordered]@{
|
||||||
'Method' = $Method
|
'Method' = $Method
|
||||||
'Uri' = $Uri
|
'Uri' = $Uri
|
||||||
'Headers' = $Headers
|
'Headers' = $Headers
|
||||||
'Timeout' = $Timeout
|
'Timeout' = $Timeout
|
||||||
'ContentType' = $ContentType
|
'ContentType' = $ContentType
|
||||||
'Body' = $Body
|
'Body' = $Body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -363,7 +367,7 @@ Describe -Name "DCIM Devices Tests" -Tag 'DCIM', 'Devices' -Fixture {
|
||||||
|
|
||||||
Mock -CommandName "Get-NetboxDCIMDevice" -ModuleName NetboxPS -MockWith {
|
Mock -CommandName "Get-NetboxDCIMDevice" -ModuleName NetboxPS -MockWith {
|
||||||
return [pscustomobject]@{
|
return [pscustomobject]@{
|
||||||
'Id' = $Id
|
'Id' = $Id
|
||||||
'Name' = $Name
|
'Name' = $Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
A description of the file.
|
A description of the file.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -28,12 +32,12 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
|
||||||
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
||||||
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
||||||
return [ordered]@{
|
return [ordered]@{
|
||||||
'Method' = $Method
|
'Method' = $Method
|
||||||
'Uri' = $Uri
|
'Uri' = $Uri
|
||||||
'Headers' = $Headers
|
'Headers' = $Headers
|
||||||
'Timeout' = $Timeout
|
'Timeout' = $Timeout
|
||||||
'ContentType' = $ContentType
|
'ContentType' = $ContentType
|
||||||
'Body' = $Body
|
'Body' = $Body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,13 +143,13 @@ Describe -Name "DCIM Interfaces Tests" -Tag 'DCIM', 'Interfaces' -Fixture {
|
||||||
|
|
||||||
It "Should add an interface to a device with lots of properties" {
|
It "Should add an interface to a device with lots of properties" {
|
||||||
$paramAddNetboxDCIMInterface = @{
|
$paramAddNetboxDCIMInterface = @{
|
||||||
Device = 123
|
Device = 123
|
||||||
Name = "TestInterface"
|
Name = "TestInterface"
|
||||||
Form_Factor = '10GBASE-T (10GE)'
|
Form_Factor = '10GBASE-T (10GE)'
|
||||||
MTU = 9000
|
MTU = 9000
|
||||||
MGMT_Only = $true
|
MGMT_Only = $true
|
||||||
Description = 'Test Description'
|
Description = 'Test Description'
|
||||||
Mode = 'Access'
|
Mode = 'Access'
|
||||||
}
|
}
|
||||||
|
|
||||||
$Result = Add-NetboxDCIMInterface @paramAddNetboxDCIMInterface
|
$Result = Add-NetboxDCIMInterface @paramAddNetboxDCIMInterface
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
A description of the file.
|
A description of the file.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -28,12 +32,12 @@ Describe -Name "DCIM Platforms Tests" -Tag 'DCIM', 'platforms' -Fixture {
|
||||||
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
||||||
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
||||||
return [ordered]@{
|
return [ordered]@{
|
||||||
'Method' = $Method
|
'Method' = $Method
|
||||||
'Uri' = $Uri
|
'Uri' = $Uri
|
||||||
'Headers' = $Headers
|
'Headers' = $Headers
|
||||||
'Timeout' = $Timeout
|
'Timeout' = $Timeout
|
||||||
'ContentType' = $ContentType
|
'ContentType' = $ContentType
|
||||||
'Body' = $Body
|
'Body' = $Body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
Helper functions Pester tests
|
Helper functions Pester tests
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -88,7 +92,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
|
|
||||||
Context -Name "Building URI components" -Fixture {
|
Context -Name "Building URI components" -Fixture {
|
||||||
It "Should give a basic hashtable" {
|
It "Should give a basic hashtable" {
|
||||||
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1}
|
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1 }
|
||||||
|
|
||||||
$URIComponents | Should -BeOfType [hashtable]
|
$URIComponents | Should -BeOfType [hashtable]
|
||||||
$URIComponents.Keys.Count | Should -BeExactly 2
|
$URIComponents.Keys.Count | Should -BeExactly 2
|
||||||
|
|
@ -100,7 +104,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should add a single ID parameter to the segments" {
|
It "Should add a single ID parameter to the segments" {
|
||||||
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123}
|
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = 123 }
|
||||||
|
|
||||||
$URIComponents | Should -BeOfType [hashtable]
|
$URIComponents | Should -BeOfType [hashtable]
|
||||||
$URIComponents.Keys.Count | Should -BeExactly 2
|
$URIComponents.Keys.Count | Should -BeExactly 2
|
||||||
|
|
@ -111,7 +115,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should add multiple IDs to the parameters id__in" {
|
It "Should add multiple IDs to the parameters id__in" {
|
||||||
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456"}
|
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'id' = "123", "456" }
|
||||||
|
|
||||||
$URIComponents | Should -BeOfType [hashtable]
|
$URIComponents | Should -BeOfType [hashtable]
|
||||||
$URIComponents.Keys.Count | Should -BeExactly 2
|
$URIComponents.Keys.Count | Should -BeExactly 2
|
||||||
|
|
@ -123,7 +127,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should skip a particular parameter name" {
|
It "Should skip a particular parameter name" {
|
||||||
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2} -SkipParameterByName 'param2'
|
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'param1' = 1; 'param2' = 2 } -SkipParameterByName 'param2'
|
||||||
|
|
||||||
$URIComponents | Should -BeOfType [hashtable]
|
$URIComponents | Should -BeOfType [hashtable]
|
||||||
$URIComponents.Keys.Count | Should -BeExactly 2
|
$URIComponents.Keys.Count | Should -BeExactly 2
|
||||||
|
|
@ -136,7 +140,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should add a query (q) parameter" {
|
It "Should add a query (q) parameter" {
|
||||||
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery'}
|
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{'query' = 'mytestquery' }
|
||||||
|
|
||||||
$URIComponents | Should -BeOfType [hashtable]
|
$URIComponents | Should -BeOfType [hashtable]
|
||||||
$URIComponents.Keys.Count | Should -BeExactly 2
|
$URIComponents.Keys.Count | Should -BeExactly 2
|
||||||
|
|
@ -150,7 +154,7 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
It "Should generate custom field parameters" {
|
It "Should generate custom field parameters" {
|
||||||
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{
|
$URIComponents = BuildURIComponents -URISegments @('segment1', 'segment2') -ParametersDictionary @{
|
||||||
'CustomFields' = @{
|
'CustomFields' = @{
|
||||||
'PRTG_Id' = 1234
|
'PRTG_Id' = 1234
|
||||||
'Customer_Id' = 'abc'
|
'Customer_Id' = 'abc'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -170,13 +174,13 @@ Describe "Helpers tests" -Tag 'Core', 'Helpers' -Fixture {
|
||||||
Mock -CommandName 'Invoke-RestMethod' -Verifiable -MockWith {
|
Mock -CommandName 'Invoke-RestMethod' -Verifiable -MockWith {
|
||||||
# Return an object of the items we would normally pass to Invoke-RestMethod
|
# Return an object of the items we would normally pass to Invoke-RestMethod
|
||||||
return [pscustomobject]@{
|
return [pscustomobject]@{
|
||||||
'Method' = $Method
|
'Method' = $Method
|
||||||
'Uri' = $Uri
|
'Uri' = $Uri
|
||||||
'Headers' = $Headers
|
'Headers' = $Headers
|
||||||
'Timeout' = $Timeout
|
'Timeout' = $Timeout
|
||||||
'ContentType' = $ContentType
|
'ContentType' = $ContentType
|
||||||
'Body' = $Body
|
'Body' = $Body
|
||||||
'results' = 'Only results'
|
'results' = 'Only results'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
IPAM Pester tests
|
IPAM Pester tests
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -29,12 +33,12 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
||||||
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
||||||
return [ordered]@{
|
return [ordered]@{
|
||||||
'Method' = $Method
|
'Method' = $Method
|
||||||
'Uri' = $Uri
|
'Uri' = $Uri
|
||||||
'Headers' = $Headers
|
'Headers' = $Headers
|
||||||
'Timeout' = $Timeout
|
'Timeout' = $Timeout
|
||||||
'ContentType' = $ContentType
|
'ContentType' = $ContentType
|
||||||
'Body' = $Body
|
'Body' = $Body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +426,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith {
|
Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith {
|
||||||
return @{
|
return @{
|
||||||
'address' = "10.1.1.1/$Id"
|
'address' = "10.1.1.1/$Id"
|
||||||
'id' = $id
|
'id' = $id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -486,7 +490,7 @@ Describe -Name "IPAM tests" -Tag 'Ipam' -Fixture {
|
||||||
Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith {
|
Mock -CommandName "Get-NetboxIPAMAddress" -ModuleName NetboxPS -MockWith {
|
||||||
return @{
|
return @{
|
||||||
'address' = '10.1.1.1/24'
|
'address' = '10.1.1.1/24'
|
||||||
'id' = $id
|
'id' = $id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
Setup function Pester tests
|
Setup function Pester tests
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -43,7 +47,7 @@ Describe "Setup tests" -Tag 'Core', 'Setup' -Fixture {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Checks the set credentials" {
|
It "Checks the set credentials" {
|
||||||
$Creds = Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText)
|
Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText)
|
||||||
(Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken"
|
(Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
Virtualization Pester tests
|
Virtualization Pester tests
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
|
||||||
|
param
|
||||||
|
(
|
||||||
|
)
|
||||||
Import-Module Pester
|
Import-Module Pester
|
||||||
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -28,12 +32,12 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
|
||||||
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
Mock -CommandName 'Invoke-RestMethod' -Verifiable -ModuleName 'NetboxPS' -MockWith {
|
||||||
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
# Return a hashtable of the items we would normally pass to Invoke-RestMethod
|
||||||
return [ordered]@{
|
return [ordered]@{
|
||||||
'Method' = $Method
|
'Method' = $Method
|
||||||
'Uri' = $Uri
|
'Uri' = $Uri
|
||||||
'Headers' = $Headers
|
'Headers' = $Headers
|
||||||
'Timeout' = $Timeout
|
'Timeout' = $Timeout
|
||||||
'ContentType' = $ContentType
|
'ContentType' = $ContentType
|
||||||
'Body' = $Body
|
'Body' = $Body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,7 +369,7 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
|
||||||
|
|
||||||
Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith {
|
Mock -CommandName "Get-NetboxVirtualMachine" -ModuleName NetboxPS -MockWith {
|
||||||
return [pscustomobject]@{
|
return [pscustomobject]@{
|
||||||
'Id' = $Id
|
'Id' = $Id
|
||||||
'Name' = $Name
|
'Name' = $Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -406,7 +410,7 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
|
||||||
|
|
||||||
Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith {
|
Mock -CommandName "Get-NetboxVirtualMachineInterface" -ModuleName NetboxPS -MockWith {
|
||||||
return [pscustomobject]@{
|
return [pscustomobject]@{
|
||||||
'Id' = $Id
|
'Id' = $Id
|
||||||
'Name' = $Name
|
'Name' = $Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -426,12 +430,12 @@ Describe -Name "Virtualization tests" -Tag 'Virtualization' -Fixture {
|
||||||
|
|
||||||
It "Should set an interface to a new name, MTU, MAC address and description" {
|
It "Should set an interface to a new name, MTU, MAC address and description" {
|
||||||
$paramSetNetboxVirtualMachineInterface = @{
|
$paramSetNetboxVirtualMachineInterface = @{
|
||||||
Id = 1234
|
Id = 1234
|
||||||
Name = 'newtestname'
|
Name = 'newtestname'
|
||||||
MAC_Address = '11:22:33:44:55:66'
|
MAC_Address = '11:22:33:44:55:66'
|
||||||
MTU = 9000
|
MTU = 9000
|
||||||
Description = "Test description"
|
Description = "Test description"
|
||||||
Force = $true
|
Force = $true
|
||||||
}
|
}
|
||||||
|
|
||||||
$Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface
|
$Result = Set-NetboxVirtualMachineInterface @paramSetNetboxVirtualMachineInterface
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue