Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/code/RegisterPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class RegisterPSResourceRepository : PSCmdlet, IDynamicParameters
/// Specifies the Api version of the repository to be set.
/// </summary>
[Parameter(ParameterSetName = NameParameterSet)]
[ValidateSet("V2", "V3", "Local", "NugetServer", "ContainerRegistry")]
public PSRepositoryInfo.APIVersion ApiVersion { get; set; }

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/code/SetPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public SwitchParameter Trusted
/// Specifies the Api version of the repository to be set.
/// </summary>
[Parameter(ParameterSetName = NameParameterSet)]
[ValidateSet("V2", "V3", "Local", "NugetServer", "ContainerRegistry")]
public PSRepositoryInfo.APIVersion ApiVersion { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ Describe "Test Register-PSResourceRepository" -tags 'CI' {
$res.ApiVersion | Should -Be 'v2'
}

It "should throw error when trying to register repository with ApiVersion unknown" {
{Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path -ApiVersion "unknown" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.PSResourceGet.Cmdlets.RegisterPSResourceRepository"

# Verify the repository was not created
$repo = Get-PSResourceRepository $TestRepoName1 -ErrorAction SilentlyContinue
$repo | Should -BeNullOrEmpty
}

It "should register container registry repository with correct ApiVersion" {
$ContainerRegistryName = "ACRRepo"
$ContainerRegistryUri = "https://psresourcegettest.azurecr.io/"
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 "ParameterArgumentValidationError,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"
}
}
Loading