Skip to content

Commit

Permalink
Merge pull request #160 from vercellone/pestermock
Browse files Browse the repository at this point in the history
Foundational Pester unit tests for #35
  • Loading branch information
joel74 authored Mar 27, 2018
2 parents 8ab3b42 + 14492a0 commit ea84665
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 42 deletions.
259 changes: 259 additions & 0 deletions F5-LTM/F5-LTM.Tests.ps1

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions F5-LTM/F5-LTM.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,28 @@ Add-Type -Path "${PSScriptRoot}\Validation.cs"
Add-Type -Path "${PSScriptRoot}\TypeData\PoshLTM.Types.cs"
Update-FormatData "${PSScriptRoot}\TypeData\PoshLTM.Format.ps1xml"
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path

#region Load Public Functions

try {
Get-ChildItem "$ScriptPath\Public" -Filter *.ps1 -Recurse| Select-Object -Expand FullName | ForEach-Object {
$Function = Split-Path $_ -Leaf
. $_
}
} catch {
Write-Warning ("{0}: {1}" -f $Function,$_.Exception.Message)
Continue
}
try {
. $_
} catch {
Write-Warning ("{0}: {1}" -f $Function,$_.Exception.Message)
}
}

#endregion

#region Load Private Functions

try {
Get-ChildItem "$ScriptPath\Private" -Filter *.ps1 -Recurse | Select-Object -Expand FullName | ForEach-Object {
$Function = Split-Path $_ -Leaf
. $_
}
} catch {
Write-Warning ("{0}: {1}" -f $Function,$_.Exception.Message)
Continue
}
Get-ChildItem "$ScriptPath\Private" -Filter *.ps1 -Recurse | Select-Object -Expand FullName | ForEach-Object {
$Function = Split-Path $_ -Leaf
try {
. $_
} catch {
Write-Warning ("{0}: {1}" -f $Function,$_.Exception.Message)
}
}

#endregion
2 changes: 1 addition & 1 deletion F5-LTM/Private/Resolve-NestedStats.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
To resolve this discrepancy, this function performs version-specific transformations to the JSON data and returns it in a standardized format with the "entries" property at the top.
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
param (
$F5Session=$Script:F5Session,

Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Public/Disable-VirtualServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
foreach($vs in $InputObject) {
$URI = $F5Session.GetLink($vs.selfLink)
$FullPath = $vs.fullPath
$JSON = Invoke-F5RestMethod -Method PATCH -Uri $URI -F5Session $F5Session -Body $JSONBody
$null = Invoke-F5RestMethod -Method PATCH -Uri $URI -F5Session $F5Session -Body $JSONBody
Get-VirtualServer -F5Session $F5Session -Name $FullPath
}
}
Expand Down
2 changes: 1 addition & 1 deletion F5-LTM/Public/Enable-VirtualServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
foreach($vs in $InputObject) {
$URI = $F5Session.GetLink($vs.selfLink)
$FullPath = $vs.fullPath
$JSON = Invoke-F5RestMethod -Method PATCH -Uri $URI -F5Session $F5Session -Body $JSONBody
$null = Invoke-F5RestMethod -Method PATCH -Uri $URI -F5Session $F5Session -Body $JSONBody
Get-VirtualServer -F5Session $F5Session -Name $FullPath
}
}
Expand Down
1 change: 1 addition & 0 deletions F5-LTM/Public/Get-PoolMemberStats.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Pool and member names are case-specific.
#>
[cmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "")]
param (
$F5Session=$Script:F5Session,

Expand Down
6 changes: 3 additions & 3 deletions F5-LTM/Public/Set-Pool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@

# This performs the magic necessary for ChgProperties to override $InputObject properties
$NewObject = Join-Object -Left $InputObject -Right ([pscustomobject]$ChgProperties) -Join FULL -WarningAction SilentlyContinue
if ($NewObject -ne $null -and $pscmdlet.ShouldProcess($F5Session.Name, "Setting Pool $Name")) {
if ($null -ne $NewObject -and $pscmdlet.ShouldProcess($F5Session.Name, "Setting Pool $Name")) {

# We only update the pool if properties other than 'Name' are passed in
If ($NewObject | Get-Member -MemberType NoteProperty | Where Name -ne 'Name'){
If ($NewObject | Get-Member -MemberType NoteProperty | Where-Object Name -ne 'Name'){

Write-Verbose -Message 'Setting Pool details...'

Expand All @@ -144,7 +144,7 @@

#endregion

$result = Invoke-F5RestMethod -Method PATCH -URI "$URI" -F5Session $F5Session -Body $JSONBody -ContentType 'application/json'
$null = Invoke-F5RestMethod -Method PATCH -URI "$URI" -F5Session $F5Session -Body $JSONBody -ContentType 'application/json'

}

Expand Down
8 changes: 4 additions & 4 deletions F5-LTM/Public/Set-VirtualServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ Function Set-VirtualServer {
if (-not $NewProperties.ContainsKey('DestinationIP')) {
$destination = if ($InputObject -and $InputObject.destination) {
$InputObject.destination
} elseif ($ExistingVirtualServer -ne $null) {
} elseif ($null -ne $ExistingVirtualServer) {
$ExistingVirtualServer.destination
}
if ($destination) { $NewProperties['DestinationIP'] = ($destination -split ':')[0] }
}
if (-not $NewProperties.ContainsKey('DestinationPort')) {
$destination = if ($InputObject -and $InputObject.destination) {
$InputObject.destination
} elseif ($ExistingVirtualServer -ne $null) {
} elseif ($null -eq $ExistingVirtualServer) {
$ExistingVirtualServer.destination
}
if ($destination) { $NewProperties['DestinationPort'] = ($destination -split ':')[1] }
Expand All @@ -243,7 +243,7 @@ Function Set-VirtualServer {
}
# This performs the magic necessary for ChgProperties to override $InputObject properties
$NewObject = Join-Object -Left $InputObject -Right ([pscustomobject]$ChgProperties) -Join FULL -WarningAction SilentlyContinue
if ($NewObject -ne $null -and $pscmdlet.ShouldProcess($F5Session.Name, "Setting VirtualServer $Name")) {
if ($null -ne $NewObject -and $pscmdlet.ShouldProcess($F5Session.Name, "Setting VirtualServer $Name")) {
Write-Verbose -Message 'Setting VirtualServer details...'

$URI = $F5Session.BaseURL + 'virtual/{0}' -f (Get-ItemPath -Name $Name -Application $Application -Partition $Partition)
Expand All @@ -259,7 +259,7 @@ Function Set-VirtualServer {

#endregion

$result = Invoke-F5RestMethod -Method PATCH -URI "$URI" -F5Session $F5Session -Body $JSONBody -ContentType 'application/json'
$null = Invoke-F5RestMethod -Method PATCH -URI "$URI" -F5Session $F5Session -Body $JSONBody -ContentType 'application/json'
}
if ($PassThru) { Get-VirtualServer -F5Session $F5Session -Name $Name -Application $Application -Partition $Partition }
}
Expand Down
24 changes: 9 additions & 15 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
# Force bootstrap of the Nuget PackageManagement Provider; Reference: http://www.powershellgallery.com/GettingStarted?section=Get%20Started
- ps: Get-PackageProvider -Name NuGet -Force
# Install pester PowerShell Unit Testing module
#- cinst -y pester
- cinst -y pester

before_test:
# Set FunctionsToExport and ModuleVersion in the module manifest (F5-LTM.psd1); Fixes #37 Do not export Private\*.ps1 functions
Expand All @@ -35,20 +35,14 @@ test_script:
# Invoke PSScriptAnalyzer against the module to make sure it's not failing any tests
- ps: Invoke-ScriptAnalyzer -Path (Join-Path $env:APPVEYOR_BUILD_FOLDER 'F5-LTM') -Recurse
# Invoke-Pester unit tests
#- ps: |
# $testResultsFile = '.\TestsResults.xml'
#
# # run tests
# $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru
#
# # upload results to AppVeyor
# (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
#
# # if failures, quit to prevent publish
# if ($res.FailedCount -gt 0) {
# throw "$($res.FailedCount) tests failed."
# }

- ps: $testResultsFile = '.\TestsResults.xml'
# run tests
- ps: $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru
# upload results to AppVeyor
- ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
# if failures, quit to prevent publish
- ps: if ($res.FailedCount -gt 0) { "$($res.FailedCount) tests failed." }

deploy_script:
# Publish module to the PowerShellGallery
- ps: Publish-Module -NugetApiKey $env:POWERSHELLGALLERY_APIKEY -Path (Join-Path $env:APPVEYOR_BUILD_FOLDER 'F5-LTM')

0 comments on commit ea84665

Please sign in to comment.