|
4 | 4 | $modPath = "$psscriptroot/../PSGetTestUtils.psm1"
|
5 | 5 | Import-Module $modPath -Force -Verbose
|
6 | 6 |
|
7 |
| -$testDir = (get-item $psscriptroot).parent.FullName |
| 7 | +$script:testDir = (get-item $psscriptroot).parent.FullName |
8 | 8 |
|
9 |
| -function CreateTestModule |
| 9 | +function script:CreateTestModule |
10 | 10 | {
|
11 | 11 | param (
|
12 | 12 | [string] $Path = "$TestDrive",
|
@@ -56,7 +56,7 @@ Describe "Test Publish-PSResource" -tags 'CI' {
|
56 | 56 | $tmpRepoPath2 = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath2"
|
57 | 57 | New-Item $tmpRepoPath2 -Itemtype directory -Force
|
58 | 58 | $testRepository2 = "testRepository2"
|
59 |
| - Register-PSResourceRepository -Name $testRepository2 -Uri $tmpRepoPath2 -ErrorAction SilentlyContinue |
| 59 | + Register-PSResourceRepository -Name $testRepository2 -Uri $tmpRepoPath2 |
60 | 60 | $script:repositoryPath2 = [IO.Path]::GetFullPath((get-psresourcerepository "testRepository2").Uri.AbsolutePath)
|
61 | 61 |
|
62 | 62 | # Create module
|
@@ -107,7 +107,7 @@ Describe "Test Publish-PSResource" -tags 'CI' {
|
107 | 107 | }
|
108 | 108 | AfterEach {
|
109 | 109 | # Delete all contents of the repository without deleting the repository directory itself
|
110 |
| - $pkgsToDelete = Join-Path -Path "$script:repositoryPath" -ChildPath "*" |
| 110 | + $pkgsToDelete = Join-Path -Path "$script:repositoryPath" -ChildPath "*" |
111 | 111 | Remove-Item $pkgsToDelete -Recurse
|
112 | 112 |
|
113 | 113 | $pkgsToDelete = Join-Path -Path "$script:repositoryPath2" -ChildPath "*"
|
@@ -151,44 +151,6 @@ Describe "Test Publish-PSResource" -tags 'CI' {
|
151 | 151 | (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath
|
152 | 152 | }
|
153 | 153 |
|
154 |
| - It "Publish should create PSResourceRepository.xml file if its not there" { |
155 |
| - # Remove the PSResourceRepository.xml file |
156 |
| - $powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PSResourceGet" |
157 |
| - $originalXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml" #this is the temporary PSResourceRepository.xml file created in the 'BeforeAll' section of this test file |
158 |
| - |
159 |
| - $tempXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "tempfortest.xml" |
160 |
| - |
161 |
| - if (Test-Path -Path $originalXmlFilePath) { |
162 |
| - Copy-Item -Path $originalXmlFilePath -Destination $tempXmlFilePath |
163 |
| - Remove-Item -Path $originalXmlFilePath -Force -ErrorAction Ignore |
164 |
| - } |
165 |
| - |
166 |
| - # Attempt to publish. |
167 |
| - # Publish-PSResource should create PSResourceRepository.xml file if not present. It will register the 'PSGallery' repository as a default, so this test will still fail |
168 |
| - # But we can ensure the PSResourceRepository.xml file is created. |
169 |
| - $version = "1.0.0" |
170 |
| - New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" |
171 |
| - |
172 |
| - Publish-PSResource -Path $script:PublishModuleBase -Repository $testRepository2 -ErrorVariable err -ErrorAction SilentlyContinue |
173 |
| - $err[0].FullyQualifiedErrorId | Should -Be "RepositoryNotRegistered,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource" |
174 |
| - |
175 |
| - $registeredRepos = Get-PSResourceRepository |
176 |
| - $registeredRepos.Count | Should -Be 1 |
177 |
| - $registeredRepos[0].Name | Should -Be $script:PSGalleryName |
178 |
| - |
179 |
| - # Cleanup |
180 |
| - # Remove the new PSResourceRepository.xml file created by the Publish-PSResource command and put back the original created in the 'BeforeAll' section of this test file |
181 |
| - if (Test-Path -Path $tempXmlFilePath) { |
182 |
| - Copy-Item -Path $tempXmlFilePath -Destination $originalXmlFilePath -Force -Verbose |
183 |
| - Remove-Item -Path $tempXmlFilePath -Force -ErrorAction Ignore |
184 |
| - } |
185 |
| - |
186 |
| - # Verify old repositories are restored |
187 |
| - $originalRegisteredRepo = Get-PSResourceRepository -Name $testRepository2 -ErrorVariable err2 -ErrorAction SilentlyContinue |
188 |
| - $err2.Count | Should -Be 0 |
189 |
| - $originalRegisteredRepo.Name | Should -Be $testRepository2 |
190 |
| - } |
191 |
| - |
192 | 154 | #region Local Source Path
|
193 | 155 | It "Publish a module with -Path and -Repository" {
|
194 | 156 | $version = "1.0.0"
|
@@ -766,3 +728,80 @@ Describe "Test Publish-PSResource" -tags 'CI' {
|
766 | 728 | }
|
767 | 729 | #>
|
768 | 730 | }
|
| 731 | + |
| 732 | + |
| 733 | +Describe "Test Publish-PSResource with Module Prefix" -tags 'CI' { |
| 734 | + |
| 735 | + BeforeAll { |
| 736 | + Get-NewPSResourceRepositoryFile |
| 737 | + |
| 738 | + $tmpRepoPath2 = Join-Path -Path $TestDrive -ChildPath "tmpRepoPath2" |
| 739 | + New-Item $tmpRepoPath2 -Itemtype directory -Force |
| 740 | + $testRepository2 = "testRepository2" |
| 741 | + Register-PSResourceRepository -Name $testRepository2 -Uri $tmpRepoPath2 |
| 742 | + $script:repositoryPath2 = [IO.Path]::GetFullPath((get-psresourcerepository "testRepository2").Uri.AbsolutePath) |
| 743 | + |
| 744 | + # Create module |
| 745 | + $script:tmpModulesPath = Join-Path -Path $TestDrive -ChildPath "tmpModulesPath" |
| 746 | + $script:PublishModuleName = "PSGetTestModule" |
| 747 | + $script:PublishModuleBase = Join-Path $script:tmpModulesPath -ChildPath $script:PublishModuleName |
| 748 | + if(!(Test-Path $script:PublishModuleBase)) |
| 749 | + { |
| 750 | + New-Item -Path $script:PublishModuleBase -ItemType Directory -Force |
| 751 | + } |
| 752 | + |
| 753 | + $script:PSGalleryName = 'PSGallery' |
| 754 | + } |
| 755 | + AfterAll { |
| 756 | + Get-RevertPSResourceRepositoryFile |
| 757 | + } |
| 758 | + AfterEach { |
| 759 | + # Delete all contents of the repository without deleting the repository directory itself |
| 760 | + $pkgsToDelete = Join-Path -Path "$script:repositoryPath2" -ChildPath "*" |
| 761 | + Remove-Item $pkgsToDelete -Recurse |
| 762 | + |
| 763 | + $pkgsToDelete = Join-Path -Path $script:PublishModuleBase -ChildPath "*" |
| 764 | + Remove-Item $pkgsToDelete -Recurse -ErrorAction SilentlyContinue |
| 765 | + } |
| 766 | + |
| 767 | + It "Publish should create PSResourceRepository.xml file if its not there" { |
| 768 | + # Remove the PSResourceRepository.xml file |
| 769 | + $powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PSResourceGet" |
| 770 | + $originalXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml" #this is the temporary PSResourceRepository.xml file created in the 'BeforeAll' section of this test file |
| 771 | + |
| 772 | + $tempXmlFilePath = Join-Path -Path $powerShellGetPath -ChildPath "tempfortest.xml" |
| 773 | + |
| 774 | + try { |
| 775 | + if (Test-Path -Path $originalXmlFilePath) { |
| 776 | + Copy-Item -Path $originalXmlFilePath -Destination $tempXmlFilePath |
| 777 | + Remove-Item -Path $originalXmlFilePath -Force -ErrorAction Ignore |
| 778 | + } |
| 779 | + |
| 780 | + # Attempt to publish. |
| 781 | + # Publish-PSResource should create PSResourceRepository.xml file if not present. It will register the 'PSGallery' repository as a default, so this test will still fail |
| 782 | + # But we can ensure the PSResourceRepository.xml file is created. |
| 783 | + $version = "1.0.0" |
| 784 | + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" |
| 785 | + |
| 786 | + Publish-PSResource -Path $script:PublishModuleBase -Repository $testRepository2 -ErrorVariable err -ErrorAction SilentlyContinue |
| 787 | + $err[0].FullyQualifiedErrorId | Should -Be "RepositoryNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource" |
| 788 | + |
| 789 | + $registeredRepos = Get-PSResourceRepository |
| 790 | + $registeredRepos.Count | Should -Be 1 |
| 791 | + $registeredRepos[0].Name | Should -Be $script:PSGalleryName |
| 792 | + } |
| 793 | + finally { |
| 794 | + # Cleanup |
| 795 | + # Remove the new PSResourceRepository.xml file created by the Publish-PSResource command and put back the original created in the 'BeforeAll' section of this test file |
| 796 | + if (Test-Path -Path $tempXmlFilePath) { |
| 797 | + Copy-Item -Path $tempXmlFilePath -Destination $originalXmlFilePath -Force -Verbose |
| 798 | + Remove-Item -Path $tempXmlFilePath -Force -ErrorAction Ignore |
| 799 | + } |
| 800 | + } |
| 801 | + |
| 802 | + # Verify old repositories are restored |
| 803 | + $originalRegisteredRepo = Get-PSResourceRepository -Name $testRepository2 -ErrorVariable err2 -ErrorAction SilentlyContinue |
| 804 | + $err2.Count | Should -Be 0 |
| 805 | + $originalRegisteredRepo.Name | Should -Be $testRepository2 |
| 806 | + } |
| 807 | +} |
0 commit comments