diff --git a/src/code/SetPSResourceRepository.cs b/src/code/SetPSResourceRepository.cs index 293db33e9..955bb207b 100644 --- a/src/code/SetPSResourceRepository.cs +++ b/src/code/SetPSResourceRepository.cs @@ -109,6 +109,7 @@ public SwitchParameter Trusted public object GetDynamicParameters() { + RepositorySettings.CheckRepositoryStore(); 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. @@ -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. diff --git a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 index 3a4d4f10c..eb244c5bd 100644 --- a/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 +++ b/test/ResourceRepositoryTests/SetPSResourceRepository.Tests.ps1 @@ -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" + $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