Skip to content
Merged
3 changes: 1 addition & 2 deletions src/code/PublishPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ protected override void ProcessRecord()
var pkgFileOrDir = new DirectoryInfo(_path);
bool isScript = _path.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase);

// TODO: think about including the repository the resource is being published to
if (!ShouldProcess(string.Format("Publish resource '{0}' from the machine.", _path)))
if (!ShouldProcess(string.Format("Publish resource '{0}' from the machine", _path)))
{
WriteVerbose("ShouldProcess is set to false.");
return;
Expand Down
10 changes: 10 additions & 0 deletions src/code/UnregisterPSResourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ protected override void BeginProcessing()
}
protected override void ProcessRecord()
{
Name = Utils.ProcessNameWildcards(Name, out string[] _, out bool nameContainsWildcard);
if (nameContainsWildcard)
{
var message = String.Format("Name: '{0}, cannot contain wildcards", String.Join(", ", Name));
var ex = new ArgumentException(message);
var NameContainsWildCardError = new ErrorRecord(ex, "nameContainsWildCardError", ErrorCategory.ReadError, null);
WriteError(NameContainsWildCardError);
return;
}

string nameArrayAsString = string.Join(", ", Name);
WriteVerbose(String.Format("removing repository {0}. Calling Remove() API now", nameArrayAsString));
if (!ShouldProcess(nameArrayAsString, "Unregister repositories from repository store"))
Expand Down
8 changes: 4 additions & 4 deletions test/FindPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Describe 'Test Find-PSResource for Module' {
$foundTestScript = $True
}

if(-not [string]::IsNullOrEmpty($item.PrereleaseLabel))
if($item.IsPrerelease)
{
$foundPreview = $True
}
Expand Down Expand Up @@ -101,7 +101,7 @@ Describe 'Test Find-PSResource for Module' {
$foundTestScript = $True
}

if(-not [string]::IsNullOrEmpty($item.PrereleaseLabel))
if($item.IsPrerelease)
{
$foundPreview = $True
}
Expand Down Expand Up @@ -210,10 +210,10 @@ Describe 'Test Find-PSResource for Module' {

It "find resource with latest (including prerelease) version given Prerelease parameter" {
# test_module resource's latest version is a prerelease version, before that it has a non-prerelease version
$res = Find-PSResource -Name "test_module" -Repository $TestGalleryName
$res = Find-PSResource -Name $testModuleName -Repository $TestGalleryName
$res.Version | Should -Be "5.0.0.0"

$resPrerelease = Find-PSResource -Name "test_module" -Prerelease -Repository $TestGalleryName
$resPrerelease = Find-PSResource -Name $testModuleName -Prerelease -Repository $TestGalleryName
$resPrerelease.Version | Should -Be "5.2.5.0"
$resPrerelease.PrereleaseLabel | Should -Be "alpha001"
}
Expand Down
33 changes: 18 additions & 15 deletions test/GetPSResourceRepository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Import-Module "$psscriptroot\PSGetTestUtils.psm1" -Force

Describe "Test Register-PSResourceRepository" {
BeforeEach {
$TestRepoName1 = "testRepository"
$TestRepoName2 = "testRepository2"
$TestRepoName3 = "testRepository3"
Get-NewPSResourceRepositoryFile
$tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1"
$tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2"
Expand All @@ -22,25 +25,25 @@ Describe "Test Register-PSResourceRepository" {
}

It "get single already registered repo" {
Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path
$res = Get-PSResourceRepository -Name "testRepository"
Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path
$res = Get-PSResourceRepository -Name $TestRepoName1
$res | Should -Not -BeNullOrEmpty
$res.Name | Should -Be "testRepository"
$res.Name | Should -Be $TestRepoName1
}

It "get all repositories matching single wildcard name" {
Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path
Register-PSResourceRepository -Name "testRepository2" -URL $tmpDir2Path
Register-PSResourceRepository -Name "testRepository3" -URL $tmpDir3Path
Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path
Register-PSResourceRepository -Name $TestRepoName2 -URL $tmpDir2Path
Register-PSResourceRepository -Name $TestRepoName3 -URL $tmpDir3Path
$res = Get-PSResourceRepository -Name "testReposit*"
foreach ($entry in $res) {
$entry.Name | Should -Match "testReposit"
}
}

It "get all repositories matching multiple wildcard names" {
Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path
Register-PSResourceRepository -Name "testRepository2" -URL $tmpDir2Path
Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path
Register-PSResourceRepository -Name $TestRepoName2 -URL $tmpDir2Path
Register-PSResourceRepository -Name "MyGallery" -URL $tmpDir3Path

$res = Get-PSResourceRepository -Name "testReposit*","*Gallery"
Expand All @@ -50,12 +53,12 @@ Describe "Test Register-PSResourceRepository" {
}

It "get all repositories matching multiple valid names provided" {
Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path
Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path
Register-PSResourceRepository -Name "MyGallery" -URL $tmpDir2Path

$res = Get-PSResourceRepository -Name "testRepository","MyGallery"
$res = Get-PSResourceRepository -Name $TestRepoName1,"MyGallery"
foreach ($entry in $res) {
$entry.Name | Should -BeIn "testRepository","MyGallery"
$entry.Name | Should -BeIn $TestRepoName1,"MyGallery"
}
}

Expand All @@ -70,16 +73,16 @@ Describe "Test Register-PSResourceRepository" {
It "given invalid and valid Names, get valid ones and write error for non valid ones" {
$nonRegisteredRepoName = "nonRegisteredRepository"

Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path
Register-PSResourceRepository -Name "testRepository2" -URL $tmpDir2Path
Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path
Register-PSResourceRepository -Name $TestRepoName2 -URL $tmpDir2Path

$res = Get-PSResourceRepository -Name "testRepository",$nonRegisteredRepoName,"testRepository2" -ErrorVariable err -ErrorAction SilentlyContinue
$res = Get-PSResourceRepository -Name $TestRepoName1,$nonRegisteredRepoName,$TestRepoName2 -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "ErrorGettingSpecifiedRepo,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResourceRepository"

# should have successfully got the other valid/registered repositories with no error
foreach ($entry in $res) {
$entry.Name | Should -BeIn "testRepository","testRepository2"
$entry.Name | Should -BeIn $TestRepoName1,$TestRepoName2
}
}

Expand Down
88 changes: 45 additions & 43 deletions test/RegisterPSResourceRepository.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ Describe "Test Register-PSResourceRepository" {
BeforeEach {
$PSGalleryName = Get-PSGalleryName
$PSGalleryURL = Get-PSGalleryLocation
$TestRepoName1 = "testRepository"
$TestRepoName2 = "testRepository2"
$TestRepoName3 = "testRepository3"
$relativeCurrentPath = Get-Location
Get-NewPSResourceRepositoryFile
$tmpDir1Path = Join-Path -Path $TestDrive -ChildPath "tmpDir1"
$tmpDir2Path = Join-Path -Path $TestDrive -ChildPath "tmpDir2"
$tmpDir3Path = Join-Path -Path $TestDrive -ChildPath "tmpDir3"
$tmpDirPaths = @($tmpDir1Path, $tmpDir2Path, $tmpDir3Path)
Get-NewTestDirs($tmpDirPaths)

$relativeCurrentPath = Get-Location
}
AfterEach {
Get-RevertPSResourceRepositoryFile
Expand All @@ -26,24 +28,24 @@ Describe "Test Register-PSResourceRepository" {
}

It "register repository given Name, URL (bare minimum for NameParmaterSet)" {
$res = Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path -PassThru
$res.Name | Should -Be "testRepository"
$res = Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path -PassThru
$res.Name | Should -Be $TestRepoName1
$res.URL.LocalPath | Should -Contain $tmpDir1Path
$res.Trusted | Should -Be False
$res.Priority | Should -Be 50
}

It "register repository with Name, URL, Trusted (NameParameterSet)" {
$res = Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path -Trusted -PassThru
$res.Name | Should -Be "testRepository"
$res = Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path -Trusted -PassThru
$res.Name | Should -Be $TestRepoName1
$res.URL.LocalPath | Should -Contain $tmpDir1Path
$res.Trusted | Should -Be True
$res.Priority | Should -Be 50
}

It "register repository given Name, URL, Trusted, Priority (NameParameterSet)" {
$res = Register-PSResourceRepository -Name "testRepository" -URL $tmpDir1Path -Trusted -Priority 20 -PassThru
$res.Name | Should -Be "testRepository"
$res = Register-PSResourceRepository -Name $TestRepoName1 -URL $tmpDir1Path -Trusted -Priority 20 -PassThru
$res.Name | Should -Be $TestRepoName1
$res.URL.LocalPath | Should -Contain $tmpDir1Path
$res.Trusted | Should -Be True
$res.Priority | Should -Be 20
Expand Down Expand Up @@ -77,23 +79,23 @@ Describe "Test Register-PSResourceRepository" {
}

It "register repositories with Repositories parameter, all name parameter style repositories (RepositoriesParameterSet)" {
$hashtable1 = @{Name = "testRepository"; URL = $tmpDir1Path}
$hashtable2 = @{Name = "testRepository2"; URL = $tmpDir2Path; Trusted = $True}
$hashtable3 = @{Name = "testRepository3"; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$hashtable1 = @{Name = $TestRepoName1; URL = $tmpDir1Path}
$hashtable2 = @{Name = $TestRepoName2; URL = $tmpDir2Path; Trusted = $True}
$hashtable3 = @{Name = $TestRepoName3; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$arrayOfHashtables = $hashtable1, $hashtable2, $hashtable3

Register-PSResourceRepository -Repositories $arrayOfHashtables
$res = Get-PSResourceRepository -Name "testRepository"
$res = Get-PSResourceRepository -Name $TestRepoName1
$res.URL.LocalPath | Should -Contain $tmpDir1Path
$res.Trusted | Should -Be False
$res.Priority | Should -Be 50

$res2 = Get-PSResourceRepository -Name "testRepository2"
$res2 = Get-PSResourceRepository -Name $TestRepoName2
$res2.URL.LocalPath | Should -Contain $tmpDir2Path
$res2.Trusted | Should -Be True
$res2.Priority | Should -Be 50

$res3 = Get-PSResourceRepository -Name "testRepository3"
$res3 = Get-PSResourceRepository -Name $TestRepoName3
$res3.URL.LocalPath | Should -Contain $tmpDir3Path
$res3.Trusted | Should -Be True
$res3.Priority | Should -Be 20
Expand All @@ -112,9 +114,9 @@ Describe "Test Register-PSResourceRepository" {
It "register repositories with Repositories parameter, name and psgallery parameter styles (RepositoriesParameterSet)" {
Unregister-PSResourceRepository -Name $PSGalleryName
$hashtable1 = @{PSGallery = $True}
$hashtable2 = @{Name = "testRepository"; URL = $tmpDir1Path}
$hashtable3 = @{Name = "testRepository2"; URL = $tmpDir2Path; Trusted = $True}
$hashtable4 = @{Name = "testRepository3"; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$hashtable2 = @{Name = $TestRepoName1; URL = $tmpDir1Path}
$hashtable3 = @{Name = $TestRepoName2; URL = $tmpDir2Path; Trusted = $True}
$hashtable4 = @{Name = $TestRepoName3; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$arrayOfHashtables = $hashtable1, $hashtable2, $hashtable3, $hashtable4

Register-PSResourceRepository -Repositories $arrayOfHashtables
Expand All @@ -124,24 +126,24 @@ Describe "Test Register-PSResourceRepository" {
$res1.Trusted | Should -Be False
$res1.Priority | Should -Be 50

$res2 = Get-PSResourceRepository -Name "testRepository"
$res2 = Get-PSResourceRepository -Name $TestRepoName1
$res2.URL.LocalPath | Should -Contain $tmpDir1Path
$res2.Trusted | Should -Be False
$res2.Priority | Should -Be 50

$res3 = Get-PSResourceRepository -Name "testRepository2"
$res3 = Get-PSResourceRepository -Name $TestRepoName2
$res3.URL.LocalPath | Should -Contain $tmpDir2Path
$res3.Trusted | Should -Be True
$res3.Priority | Should -Be 50

$res4 = Get-PSResourceRepository -Name "testRepository3"
$res4 = Get-PSResourceRepository -Name $TestRepoName3
$res4.URL.LocalPath | Should -Contain $tmpDir3Path
$res4.Trusted | Should -Be True
$res4.Priority | Should -Be 20
}

It "not register repository when Name is provided but URL is not" {
{Register-PSResourceRepository -Name "testRepository" -URL "" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository"
{Register-PSResourceRepository -Name $TestRepoName1 -URL "" -ErrorAction Stop} | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository"
}

It "not register repository when Name is empty but URL is provided" {
Expand Down Expand Up @@ -172,24 +174,24 @@ Describe "Test Register-PSResourceRepository" {
It "not register incorrectly formatted PSGallery type repo among correct ones when incorrect type is <Type>" -TestCases $testCases {
param($Type, $IncorrectHashTable)

$correctHashtable1 = @{Name = "testRepository"; URL = $tmpDir1Path}
$correctHashtable2 = @{Name = "testRepository2"; URL = $tmpDir2Path; Trusted = $True}
$correctHashtable3 = @{Name = "testRepository3"; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$correctHashtable1 = @{Name = $TestRepoName1; URL = $tmpDir1Path}
$correctHashtable2 = @{Name = $TestRepoName2; URL = $tmpDir2Path; Trusted = $True}
$correctHashtable3 = @{Name = $TestRepoName3; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$arrayOfHashtables = $correctHashtable1, $correctHashtable2, $IncorrectHashTable, $correctHashtable3

Unregister-PSResourceRepository -Name "PSGallery"
Unregister-PSResourceRepository -Name $PSGalleryName
Register-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "NotProvideNameUrlForPSGalleryRepositoriesParameterSetRegistration,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository"

$res = Get-PSResourceRepository -Name "testRepository"
$res.Name | Should -Be "testRepository"
$res = Get-PSResourceRepository -Name $TestRepoName1
$res.Name | Should -Be $TestRepoName1

$res2 = Get-PSResourceRepository -Name "testRepository2"
$res2.Name | Should -Be "testRepository2"
$res2 = Get-PSResourceRepository -Name $TestRepoName2
$res2.Name | Should -Be $TestRepoName2

$res3 = Get-PSResourceRepository -Name "testRepository3"
$res3.Name | Should -Be "testRepository3"
$res3 = Get-PSResourceRepository -Name $TestRepoName3
$res3.Name | Should -Be $TestRepoName3
}

$testCases2 = @{Type = "-Name is not specified"; IncorrectHashTable = @{URL = $tmpDir1Path}; ErrorId = "NullNameForRepositoriesParameterSetRegistration,Microsoft.PowerShell.PowerShellGet.Cmdlets.RegisterPSResourceRepository"},
Expand All @@ -200,32 +202,32 @@ Describe "Test Register-PSResourceRepository" {
It "not register incorrectly formatted Name type repo among correct ones when incorrect type is <Type>" -TestCases $testCases2 {
param($Type, $IncorrectHashTable, $ErrorId)

$correctHashtable1 = @{Name = "testRepository2"; URL = $tmpDir2Path; Trusted = $True}
$correctHashtable2 = @{Name = "testRepository3"; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$correctHashtable1 = @{Name = $TestRepoName2; URL = $tmpDir2Path; Trusted = $True}
$correctHashtable2 = @{Name = $TestRepoName3; URL = $tmpDir3Path; Trusted = $True; Priority = 20}
$correctHashtable3 = @{PSGallery = $True; Priority = 30};

$arrayOfHashtables = $correctHashtable1, $correctHashtable2, $IncorrectHashTable, $correctHashtable3
Unregister-PSResourceRepository -Name "PSGallery"
Unregister-PSResourceRepository -Name $PSGalleryName
Register-PSResourceRepository -Repositories $arrayOfHashtables -ErrorVariable err -ErrorAction SilentlyContinue
$err.Count | Should -Not -Be 0
$err[0].FullyQualifiedErrorId | Should -BeExactly $ErrorId

$res = Get-PSResourceRepository -Name "testRepository2"
$res.Name | Should -Be "testRepository2"
$res = Get-PSResourceRepository -Name $TestRepoName2
$res.Name | Should -Be $TestRepoName2

$res2 = Get-PSResourceRepository -Name "testRepository3"
$res2.Name | Should -Be "testRepository3"
$res2 = Get-PSResourceRepository -Name $TestRepoName3
$res2.Name | Should -Be $TestRepoName3

$res3 = Get-PSResourceRepository -Name "PSGallery"
$res3.Name | Should -Be "PSGallery"
$res3 = Get-PSResourceRepository -Name $PSGalleryName
$res3.Name | Should -Be $PSGalleryName
$res3.Priority | Should -Be 30
}

It "should register repository with relative location provided as URL" {
Register-PSResourceRepository -Name "testRepository" -URL "./"
$res = Get-PSResourceRepository -Name "testRepository"
Register-PSResourceRepository -Name $TestRepoName1 -URL "./"
$res = Get-PSResourceRepository -Name $TestRepoName1

$res.Name | Should -Be "testRepository"
$res.Name | Should -Be $TestRepoName1
$res.URL.LocalPath | Should -Contain $relativeCurrentPath
$res.Trusted | Should -Be False
$res.Priority | Should -Be 50
Expand Down
Loading