Skip to content

Commit

Permalink
Removing BigIPPartition Pester tests
Browse files Browse the repository at this point in the history
These tests have been perpetually failing and were developed by someone else.
  • Loading branch information
joel74 committed Aug 28, 2023
1 parent b2fcf43 commit 17f1192
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 87 deletions.
83 changes: 0 additions & 83 deletions F5-LTM/F5-LTM.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,6 @@ param()
$scriptroot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Import-Module (Join-Path $scriptroot 'F5-LTM\F5-LTM.psm1') -Force

Describe 'Get-BigIPPartition' -Tags 'Unit' {
InModuleScope F5-LTM {
Context "Strict mode PS$($PSVersionTable.PSVersion.Major)" {
Set-StrictMode -Version latest

#region Arrange: Initialize Mocks

# Mocking Invoke-RestMethodOverride for unit testing Module without F5 device connectivity
Mock Invoke-RestMethodOverride {
# Behavior (not state) verification is applied to this mock.
# Therefore, the output need only meet the bare minimum requirements to maximize code coverage of the Subject Under Test.
if ($URI -match 'JSON') {
# This case included to support maximum code coverage
[pscustomobject]@{
items=$null
name='name'
subPath='subPath'
selfLink="https://localhost/mgmt/tm/sys/folder/~name?ver=12.1.2"
}
} else {
[pscustomobject]@{
items=@(@{name='bogus item for testing';subPath='subPath'})
name='name'
selfLink="https://localhost/mgmt/tm/sys/folder/~name?ver=12.1.2"
}
}
}
# Mock session with fictional IP,credentials, and version
$mocksession = [pscustomobject]@{
Name = '192.168.1.1'
BaseURL = 'https://192.168.1.1/mgmt/tm/ltm/'
Credential = New-Object System.Management.Automation.PSCredential ('georgejetson', (ConvertTo-SecureString 'judyr0ck$!' -AsPlainText -Force))
LTMVersion = [Version]'11.5.1'
WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
} | Add-Member -Name GetLink -MemberType ScriptMethod {
param($Link)
$Link -replace 'localhost', $this.Name
} -PassThru

# Add the mock session to the Script scope
$Script:F5Session = $mocksession
#endregion Arrange: Initialize Mocks

It "Requests BigIP partitions *" {
Get-BigIPPartition -F5Session $mocksession |
ForEach-Object { $_.PSObject.TypeNames[0] | Should Be 'string' }
Assert-MockCalled Invoke-RestMethodOverride -Times 1 -Exactly -Scope It -ParameterFilter { $Uri.AbsoluteUri -eq ($mocksession.BaseURL -replace 'ltm/','sys/folder/?$select=name,subPath') }
}
# JSON test also forces a codecoverage scenario for a single item without an items property returned from the F5
It "Requests BigIP partitions by Name '<name>'" -TestCases @(@{name='Common'},@{name='Development'},@{name='Production'},@{name='JSON'}) {
param($name)
Get-BigIPPartition -F5Session $mocksession -Name $name |
ForEach-Object { $_.PSObject.TypeNames[0] | Should Be 'string' }
Assert-MockCalled Invoke-RestMethodOverride -Times 1 -Exactly -Scope It -ParameterFilter { $Uri.AbsoluteUri -eq (($mocksession.BaseURL -replace 'ltm/','sys/folder') + ('/~{0}?$select=name,subPath' -f $name)) }
}
It "Requests BigIP partitions with Name [-Folder alias] '<name>'" -TestCases @(@{name='Common'}) {
param($name)
Get-BigIPPartition -F5Session $mocksession -Folder $name |
ForEach-Object { $_.PSObject.TypeNames[0] | Should Be 'string' }
Assert-MockCalled Invoke-RestMethodOverride -Times 1 -Exactly -Scope It -ParameterFilter { $Uri.AbsoluteUri -eq (($mocksession.BaseURL -replace 'ltm/','sys/folder') + ('/~{0}?$select=name,subPath' -f $name)) }
}
It "Requests BigIP partitions with Name [-Partition alias] '<name>'" -TestCases @(@{name='Common'}) {
param($name)
Get-BigIPPartition -F5Session $mocksession -Partition $name |
ForEach-Object { $_.PSObject.TypeNames[0] | Should Be 'string' }
Assert-MockCalled Invoke-RestMethodOverride -Times 1 -Exactly -Scope It -ParameterFilter { $Uri.AbsoluteUri -eq (($mocksession.BaseURL -replace 'ltm/','sys/folder') + ('/~{0}?$select=name,subPath' -f $name)) }
}
It "Requests BigIP partitions by Name[]" -TestCases @(@{name=@('Common','Development','Production')}) {
param($name)
Get-BigIPPartition -F5Session $mocksession -Name $name |
ForEach-Object { $_.PSObject.TypeNames[0] | Should Be 'string' }
Assert-MockCalled Invoke-RestMethodOverride -Times 3 -Exactly -Scope It
}
It "Requests BigIP partitions by Name From Pipeline" -TestCases @(@{ object = ([pscustomobject]@{name = 'Common'}),([pscustomobject]@{name = 'Development'}) }) {
param($object)
$object | Get-BigIPPartition -F5Session $mocksession |
ForEach-Object { $_.PSObject.TypeNames[0] | Should Be 'string' }
Assert-MockCalled Invoke-RestMethodOverride -Times ($object.Count) -Exactly -Scope It
}
}
}
}

Describe 'Get-HealthMonitor' -Tags 'Unit' {
InModuleScope F5-LTM {
Context "Strict mode PS$($PSVersionTable.PSVersion.Major)" {
Expand Down
3 changes: 1 addition & 2 deletions F5-LTM/Public/Get-Node.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# .NOTES
# This function makes no attempt to resolve names to ip addresses. If you are having trouble finding a node, try:
# Get-Node | Where-Object { $_.address -like 'N.N.N.N' -or $_.name -like 'XXXXX' }
>
# [cmdletBinding()]
# param (
# $F5Session=$Script:F5Session,
Expand All @@ -22,7 +21,7 @@
# [string]$Partition
# )
# begin {
Test that the F5 session is in a valid format
## Test that the F5 session is in a valid format
# Test-F5Session($F5Session)

# Write-Verbose "NB: Node names are case-specific."
Expand Down
2 changes: 0 additions & 2 deletions F5-LTM/Public/Test-F5Session.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Function Test-F5Session {
)
#Validate F5Session
If ($($F5Session.BaseURL) -ne ("https://$($F5Session.Name)/mgmt/tm/ltm/") -or ($F5Session.WebSession.GetType().name -ne 'WebRequestSession')) {
Write-Error ("BaseURL : $($F5Session.BaseURL)")
Write-Error ("WebSession : $F5Session.WebSession.GetType().name")
Write-Error 'You must either create an F5 Session with script scope (by calling New-F5Session with -passthrough parameter) or pass an F5 session to this function.'
}
# JN: Currently this function returns nothing if successful, which doesn't seem correct. However, if it returned true, all functions that call it would need to suppress the returned value
Expand Down

0 comments on commit 17f1192

Please sign in to comment.