Skip to content
Open
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
6 changes: 1 addition & 5 deletions src/code/SetPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public SwitchParameter Trusted

public object GetDynamicParameters()
{
RepositorySettings.CheckRepositoryStore();
Comment thread
alerickson marked this conversation as resolved.
PSRepositoryInfo repository = RepositorySettings.Read(new[] { Name }, out string[] _).FirstOrDefault();
// Dynamic parameter '-CredentialProvider' should not appear for PSGallery, MAR, or any container registry repository.
// It should also not appear when using the 'Repositories' parameter set.
Expand All @@ -129,11 +130,6 @@ public object GetDynamicParameters()

#region Private methods

protected override void BeginProcessing()
{
RepositorySettings.CheckRepositoryStore();
}

protected override void ProcessRecord()
{
// determine if either 1 of 5 values are attempting to be set: Uri, Priority, Trusted, APIVersion, CredentialInfo.
Expand Down
14 changes: 14 additions & 0 deletions test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ Describe "Test Set-PSResourceRepository" -tags 'CI' {
Get-RemoveTestDirs($tmpDirPaths)
}

It "set PSGallery trust when repository store file doesn't exist" {
$powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PSResourceGet"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected path construction should be platform specific.

$repoFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml"
Remove-Item -LiteralPath $repoFilePath -Force -ErrorAction Stop
Test-Path -LiteralPath $repoFilePath | Should -Be False

$result = Set-PSResourceRepository -Name PSGallery -Trusted -PassThru -ErrorAction Stop

Test-Path -LiteralPath $repoFilePath | Should -Be True
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be $PSGalleryName
$result.Trusted | Should -Be True
}

It "set repository given Name and Uri parameters" {
Register-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir1Path
Set-PSResourceRepository -Name $TestRepoName1 -Uri $tmpDir2Path
Expand Down
Loading