Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active January 5, 2023 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/9b164ef48631b0d0ee5a404b11736ee8 to your computer and use it in GitHub Desktop.
Save techthoughts2/9b164ef48631b0d0ee5a404b11736ee8 to your computer and use it in GitHub Desktop.
Pester test a command that should be called with certain parameters
# test a command that should be called with certain parameters
#------------------------------------------------------------------------------
It 'should call the API with the expected parameters' {
Mock -CommandName Invoke-RestMethod {
} -Verifiable -ParameterFilter { $Uri -like 'https://api.telegram.org/bot*getStickerSet*' }
# "https://api.telegram.org/bot$BotToken/getStickerSet"
$getTelegramStickerPackInfoSplat = @{
BotToken = $token
StickerSetName = 'STPicard'
}
Get-TelegramStickerPackInfo @getTelegramStickerPackInfoSplat
Assert-VerifiableMock
} #it
#------------------------------------------------------------------------------
It 'should call the API with the expected parameters' {
Mock -CommandName Invoke-RestMethod {
$Uri | Should -BeExactly 'https://api.github.com/repos/Azure/azure-powershell/releases'
$ContentType | Should -BeExactly 'application/json'
$ErrorAction | Should -BeExactly 'Stop'
} -Verifiable
Get-GitHubReleaseInfo -RepositoryName 'Azure/azure-powershell' | Should -InvokeVerifiable
} #it
#------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment