Skip to content

Commit

Permalink
(WIP) Remove query string from Pester tests
Browse files Browse the repository at this point in the history
For some reason locally I am seeing either the `Search()` or `Packages()` endpoint in the `choco search` test. Instead of looking for that specifically, we should be able to filter down like this.
  • Loading branch information
corbob committed Nov 21, 2024
1 parent 1353106 commit 5e0848b
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions tests/pester-tests/features/CredentialProvider.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
Describe 'Ensuring credentials do not bleed from configured sources' -Tag CredentialProvider -ForEach @(
@{
Command = 'info'
QueryString = "/Packages()?`$filter=(tolower(Id)%20eq%20'chocolatey-compatibility.extension')%20and%20IsLatestVersion&semVerLevel=2.0.0"
ExitCode = 0
}
@{
Command = 'install'
QueryString = "/Packages()?`$filter=(tolower(Id)%20eq%20'chocolatey-compatibility.extension')%20and%20IsLatestVersion&semVerLevel=2.0.0"
ExitCode = 1
}
@{
Command = 'outdated'
# The QueryString here is emitted for each package installed. The chocolatey package is the only one we can be sure is present.
QueryString = "/Packages()?`$filter=tolower(Id)%20eq%20'chocolatey'&semVerLevel=2.0.0"
ExitCode = 0
}
@{
Command = 'search'
#
QueryString = "/Packages()?`$filter=((((Id%20ne%20null)%20and%20substringof('chocolatey-compatibility.extension',tolower(Id)))%20or%20((Description%20ne%20null)%20and%20substringof('chocolatey-compatibility.extension',tolower(Description))))%20or%20((Tags%20ne%20null)%20and%20substringof('%20chocolatey-compatibility.extension%20',tolower(Tags))))%20and%20IsLatestVersion&`$orderby=Id&`$skip=0&`$top=30&semVerLevel=2.0.0"
ExitCode = 1
}
@{
Command = 'upgrade'
QueryString = "/Packages()?`$filter=(tolower(Id)%20eq%20'chocolatey-compatibility.extension')%20and%20IsLatestVersion&semVerLevel=2.0.0"
ExitCode = 1
}
@{
Command = 'download'
QueryString = "/Packages()?`$filter=(tolower(Id)%20eq%20'chocolatey-compatibility.extension')%20and%20IsLatestVersion&semVerLevel=2.0.0"
ExitCode = 1
}
) {
Expand Down Expand Up @@ -63,7 +55,8 @@
}

It 'Outputs error message' {
$Output.Lines | Should -Contain "Failed to fetch results from V2 feed at '$($SetupSource.Url.Trim('/'))$QueryString' with following message : Response status code does not indicate success: 401 (Unauthorized)." -Because $Output.String
$FilteredOutput = $Output.Lines -match "Failed to fetch results from V2 feed at '$($SetupSource.Url.Trim('/'))"
$FilteredOutput.Count | Should -BeGreaterOrEqual 1 -Because $Output.String
}
}
}

0 comments on commit 5e0848b

Please sign in to comment.