-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Repair Get-NB* to work for objects with no custom fields. * Patch New-nbObject to understand lookups. * Fix a few tests. Some pester bugs. * Patch -Search on Get-nb*. * Change Pester options for local "Invoke-Build" runs.
- Loading branch information
Showing
7 changed files
with
92 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ function Get-nbObject { | |
$Query['q'] = $Search | ||
} else { | ||
$Query = @{ | ||
s = $Search | ||
q = $Search | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.1.1 | ||
2.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
#Describe 'New object passes stuff through' { | ||
# it "should call invoke-nbApi with the proper passthrough" { | ||
# $token = ConvertTo-SecureString -String "APITOKEN" -AsPlainText -Force | ||
# Connect-nbAPI -APIurl 'http://example.com' -Token $token | ||
# $object = @{ | ||
# name = "NewDevice" | ||
# serial = "Example" | ||
# } | ||
# #need to insert the object into the parameter filter | ||
# #$ParameterFilter = { | ||
# # $body -eq 'BODYTEXT' -and | ||
# # $resource -eq "dcim/devices" -and | ||
# # $HttpVerb -eq [Microsoft.PowerShell.Commands.WebRequestMethod]::Post | ||
# #} | ||
# #$ParameterFilter = $ParameterFilter.ToString() -replace 'BODYTEXT', ($object | ConvertTo-Json -Compress) | ||
# #$ParameterFilter = [scriptblock]::Create($ParameterFilter) | ||
# Mock Invoke-nbApi -MockWith {} -ModuleName powerbox #-Verifiable -ParameterFilter $ParameterFilter | ||
# | ||
# New-nbObject -Resource dcim/devices @object | ||
# Assert-MockCalled -CommandName Invoke-nbApi -Times 1 | ||
# #Assert-VerifiableMock | ||
# } | ||
# it "Should passsthrough even with lookups" { | ||
# $object = @{ | ||
# name = "NewDevice" | ||
# serial = "Example" | ||
# device_type = "Something" | ||
# } | ||
# $lookup = @{ | ||
# device_type = 'dcim/device-types' | ||
# } | ||
# Mock Invoke-nbApi { } # -ModuleName powerbox #-Verifiable -ParameterFilter { | ||
# # $body -eq '{"Name":"NewDevice","Serial":"Example","device-type":0}' -and | ||
# # $resource -eq 'dcim/devices' -and | ||
# # $HttpVerb -eq [Microsoft.PowerShell.Commands.WebRequestMethod]::Post | ||
# #} | ||
# Mock ConvertTo-nbID {return 0} #-ModuleName powerbox #-Verifiable -ParameterFilter { | ||
# # $source -eq 'dcim/device-types' -and | ||
# # $value -eq 'Something' | ||
# #} | ||
# {New-nbObject -Resource dcim/devices -Lookup $lookup @object} | | ||
# Should -not -Throw | ||
# Assert-MockCalled -CommandName Invoke-nbApi -Times 1 -Exactly | ||
# Assert-MockCalled -CommandName ConvertTo-nbID -Times 1 -Exactly | ||
# #Assert-VerifiableMock | ||
# } | ||
#} | ||
Describe 'New object passes stuff through' { | ||
BeforeEach { | ||
$token = ConvertTo-SecureString -String "APITOKEN" -AsPlainText -Force | ||
Connect-nbAPI -APIurl 'http://example.com' -Token $token | ||
} | ||
it "should call invoke-nbApi with the proper passthrough" { | ||
$object = [pscustomobject]@{ | ||
name = "NewDevice" | ||
serial = "Example" | ||
} | ||
|
||
Mock Invoke-nbApi -MockWith {} -ModuleName powerbox -Verifiable | ||
{New-nbObject -Resource dcim/devices -Object $object} | should -not -Throw | ||
#TODO: Submit bug report to pester on why this doesn't work with the parameter filter. | ||
Assert-MockCalled -CommandName Invoke-nbApi -Times 1 -ModuleName powerbox <#-ParameterFilter { | ||
$body -eq '{"Name":"NewDevice","Serial":"Example"}' -and | ||
$resource -eq "dcim/devices" -and | ||
$HttpVerb -eq 'POST' | ||
}#> | ||
} | ||
it "Should passsthrough even with lookups" { | ||
$object = [pscustomobject]@{ | ||
name = "NewDevice" | ||
serial = "Example" | ||
device_type = "Something" | ||
} | ||
$lookup = @{ | ||
device_type = 'dcim/device-types' | ||
} | ||
Mock Invoke-nbApi {} -ModuleName powerbox -Verifiable | ||
Mock ConvertTo-nbID {return 0} -ModuleName powerbox | ||
{New-nbObject -Resource dcim/devices -Lookup $lookup -object $object } | Should -not -Throw | ||
Assert-MockCalled -CommandName Invoke-nbApi -Times 2 -Exactly -ModuleName powerbox <#-ParameterFilter { | ||
$body -eq '{"Name":"NewDevice","Serial":"Example","device-type":0}' -and | ||
$resource -eq 'dcim/devices' -and | ||
$HttpVerb -eq [Microsoft.PowerShell.Commands.WebRequestMethod]::Post | ||
}#> | ||
Assert-MockCalled -CommandName ConvertTo-nbID -Times 1 -Exactly -ModuleName powerbox | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Describe 'Set object passes stuff through' { | ||
BeforeEach { | ||
$token = ConvertTo-SecureString -String "APITOKEN" -AsPlainText -Force | ||
Connect-nbAPI -APIurl 'http://example.com' -Token $token | ||
} | ||
it "should call invoke-nbApi with the proper passthrough" { | ||
$object = [pscustomobject]@{ | ||
name = "NewDevice" | ||
serial = "Example" | ||
} | ||
|
||
Mock Invoke-nbApi -MockWith {} -ModuleName powerbox -Verifiable | ||
{Set-nbObject -Id 1 -Resource dcim/devices -Object $object} | should -not -Throw | ||
#TODO: Submit bug report to pester on why this doesn't work with the parameter filter. | ||
Assert-MockCalled -CommandName Invoke-nbApi -Times 1 -ModuleName powerbox <#-ParameterFilter { | ||
$Id -eq 1 -and | ||
$body -eq '{"Name":"NewDevice","Serial":"Example"}' -and | ||
$resource -eq "dcim/devices" -and | ||
$HttpVerb -eq 'POST' | ||
}#> | ||
} | ||
it "Should passsthrough even with lookups" { | ||
$object = [pscustomobject]@{ | ||
name = "NewDevice" | ||
serial = "Example" | ||
device_type = "Something" | ||
} | ||
$lookup = @{ | ||
device_type = 'dcim/device-types' | ||
} | ||
Mock Invoke-nbApi {} -ModuleName powerbox -Verifiable | ||
Mock ConvertTo-nbID {return 0} -ModuleName powerbox | ||
{Set-nbObject -Id 1 -Resource dcim/devices -Lookup $lookup -object $object } | Should -not -Throw | ||
Assert-MockCalled -CommandName Invoke-nbApi -Times 2 -Exactly -ModuleName powerbox <#-ParameterFilter { | ||
$Id -eq 1 -and | ||
$body -eq '{"Name":"NewDevice","Serial":"Example","device-type":0}' -and | ||
$resource -eq 'dcim/devices' -and | ||
$HttpVerb -eq [Microsoft.PowerShell.Commands.WebRequestMethod]::Post | ||
}#> | ||
Assert-MockCalled -CommandName ConvertTo-nbID -Times 1 -Exactly -ModuleName powerbox | ||
} | ||
} |