Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/code/SetPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ protected override void ProcessRecord()
PSRepositoryInfo.APIVersion? repoApiVersion = null;
if (MyInvocation.BoundParameters.ContainsKey(nameof(ApiVersion)))
{
if (ApiVersion == PSRepositoryInfo.APIVersion.Unknown)
{
ThrowTerminatingError(new ErrorRecord(
new ArgumentException("ApiVersion 'Unknown' is not a valid value for Set-PSResourceRepository. Valid values are: V2, V3, Local, NugetServer, ContainerRegistry"),
"InvalidApiVersion",
ErrorCategory.InvalidArgument,
this));
}
repoApiVersion = ApiVersion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,16 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' {
$repo.Priority | Should -Be 25
}

It "should not change ApiVersion of repository if -ApiVersion parameter was not used" {
It "should throw error when trying to set ApiVersion to unknown" {
Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path
$repo = Get-PSResourceRepository $TestRepoName1
$repoApiVersion = $repo.ApiVersion
$repoApiVersion | Should -Be "local"

Set-PSResourceRepository -Name $TestRepoName1 -ApiVersion "unknown" -ErrorVariable err -ErrorAction SilentlyContinue
{Set-PSResourceRepository -Name $TestRepoName1 -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "InvalidApiVersion,Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSResourceRepository"

# Verify the repository ApiVersion was not changed
$repo = Get-PSResourceRepository $TestRepoName1
$repo.ApiVersion | Should -Be "unknown"
$err.Count | Should -Be 0
$repo.ApiVersion | Should -Be "local"
}
}