ps/Modules/Alkami.PowerShell.Configuration/Public/Get-NewRelicNextLink.tests.ps1

41 lines
1.9 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "Get-NewRelicNextLink" {
Context "Has garbage input" {
It "Throws on garbage input" {
{ (Get-NewRelicNextLink -LinkHeader "garbage input") } | Should -Throw
}
}
Context "Has empty input" {
$isEmpty = (Get-NewRelicNextLink -LinkHeader "")
It "is empty" {
$isEmpty | Should -BeNull
}
}
Context "Has correct input" {
# this test has no spaces between ; and rel - This is test case #1 for parsing the values
$isRight = (Get-NewRelicNextLink -LinkHeader '<https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=1>;rel="first", <https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=18>;rel="prev", <https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=20>;rel="next", <https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=20>;rel="last"')
It "is the expected value" {
$isRight | Should -Be "https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=20"
}
}
Context "Has correct input but the expected type is not present" {
# this test has one space between ; and rel - This is test case #2 for parsing the values
$isRight = (Get-NewRelicNextLink -LinkHeader '<https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=1>; rel="first", <https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=18>; rel="prev", <https://api.newrelic.com/v2/applications/5313884/metrics.xml?page=20>; rel="next"' -LinkType 'last')
It "is empty" {
$isEmpty | Should -BeNull
}
}
}