Skip to content

Commit 0899e49

Browse files
Fix tests
1 parent c3747b3 commit 0899e49

5 files changed

Lines changed: 31 additions & 56 deletions

File tree

test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
273273
}
274274

275275
Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' {
276-
BeforeAll {
277-
Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry"
278-
}
279-
280-
AfterAll {
281-
Unregister-PSResourceRepository -Name "MAR"
282-
}
283276

284277
It "Should find resource given specific Name, Version null" {
285278
$res = Find-PSResource -Name "Az.Accounts" -Repository "MAR"
@@ -313,10 +306,10 @@ Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' {
313306
It "Should find version range for Az dependencies" {
314307
# Target known version to know the output from the API won't change
315308
$res = Find-PSResource -Repository 'MAR' -Name 'Az' -Version '14.4.0'
316-
309+
317310
# Version defined by "ModuleVersion"
318311
$res.Dependencies.Where{$_.'Name' -eq 'Az.Accounts'}.'VersionRange'.ToString() | Should -Be '[5.3.0, )'
319-
312+
320313
# Version defined by "RequiredVersion"
321314
$res.Dependencies.Where{$_.'Name' -eq 'Az.Resources'}.'VersionRange'.ToString() | Should -Be '[8.1.0, 8.1.0]'
322315
}

test/InstallPSResourceTests/InstallPSResourceContainerRegistryServer.Tests.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,6 @@ Describe 'Test Install-PSResource for Container Registry scenarios - Manual Vali
351351
}
352352

353353
Describe 'Test Install-PSResource for MAR Repository' -tags 'CI' {
354-
BeforeAll {
355-
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", "azure-powershell/");
356-
Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry"
357-
}
358-
359-
AfterAll {
360-
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", $null);
361-
Unregister-PSResourceRepository -Name "MAR"
362-
}
363354

364355
It "Should find resource given specific Name, Version null" {
365356
try {

test/PublishPSResourceTests/PublishPSResourceContainerRegistryServer.Tests.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,6 @@ Describe "Test Publish-PSResource" -tags 'CI' {
590590
}
591591

592592
Describe 'Test Publish-PSResource for MAR Repository' -tags 'CI' {
593-
BeforeAll {
594-
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", "azure-powershell/");
595-
Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry"
596-
}
597-
598-
AfterAll {
599-
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", $null);
600-
Unregister-PSResourceRepository -Name "MAR"
601-
}
602593

603594
It "Should find resource given specific Name, Version null" {
604595
$fileName = "NonExistent.psd1"

test/ResourceRepositoryTests/MARRepository.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Describe "Test MAR Repository Registration" -tags 'CI' {
7777

7878
Context "Reset repository store includes MAR" {
7979
It "Reset-PSResourceRepository should register MAR alongside PSGallery" {
80-
Reset-PSResourceRepository -Force
80+
Reset-PSResourceRepository
8181
$res = Get-PSResourceRepository -Name $MARName
8282
$res | Should -Not -BeNullOrEmpty
8383
$res.Name | Should -Be $MARName
@@ -95,7 +95,7 @@ Describe "Test MAR Repository Registration" -tags 'CI' {
9595
$res = Get-PSResourceRepository -Name $MARName -ErrorAction SilentlyContinue
9696
$res | Should -BeNullOrEmpty
9797

98-
Reset-PSResourceRepository -Force
98+
Reset-PSResourceRepository
9999
$res = Get-PSResourceRepository -Name $MARName
100100
$res | Should -Not -BeNullOrEmpty
101101
$res.Name | Should -Be $MARName
@@ -107,7 +107,7 @@ Describe "Test MAR Repository Registration" -tags 'CI' {
107107
It "Reset-PSResourceRepository should restore both PSGallery and MAR" {
108108
Unregister-PSResourceRepository -Name $MARName
109109
Unregister-PSResourceRepository -Name $PSGalleryName
110-
Reset-PSResourceRepository -Force
110+
Reset-PSResourceRepository
111111

112112
$mar = Get-PSResourceRepository -Name $MARName
113113
$mar | Should -Not -BeNullOrEmpty

test/ResourceRepositoryTests/ResetPSResourceRepository.Tests.ps1

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ Describe "Test Reset-PSResourceRepository" -tags 'CI' {
2222
$tmpDirPath = Join-Path -Path $TestDrive -ChildPath "tmpDir1"
2323
New-Item -ItemType Directory -Path $tmpDirPath -Force | Out-Null
2424
Register-PSResourceRepository -Name $TestRepoName -Uri $tmpDirPath
25-
25+
2626
# Verify repository was added
2727
$repos = Get-PSResourceRepository
2828
$repos.Count | Should -BeGreaterThan 1
29-
29+
3030
# Act: Reset repository store
3131
Reset-PSResourceRepository -Confirm:$false
32-
32+
3333
# Assert: Only PSGallery should exist
3434
$repos = Get-PSResourceRepository
35-
$repos.Count | Should -Be 1
35+
$repos.Count | Should -Be 2
3636
$repos.Name | Should -Be $PSGalleryName
3737
$repos.Uri | Should -Be $PSGalleryUri
3838
}
@@ -43,20 +43,20 @@ Describe "Test Reset-PSResourceRepository" -tags 'CI' {
4343
$tmpDirPath = Join-Path -Path $TestDrive -ChildPath "tmpDir1"
4444
New-Item -ItemType Directory -Path $tmpDirPath -Force | Out-Null
4545
Register-PSResourceRepository -Name $TestRepoName -Uri $tmpDirPath
46-
46+
4747
# Act: Reset repository store with PassThru
4848
$result = Reset-PSResourceRepository -Confirm:$false -PassThru
49-
49+
5050
# Assert: Result should be PSGallery repository info
5151
$result | Should -Not -BeNullOrEmpty
5252
$result.Name | Should -Be $PSGalleryName
5353
$result.Uri | Should -Be $PSGalleryUri
5454
$result.Trusted | Should -Be $false
5555
$result.Priority | Should -Be 50
56-
56+
5757
# Verify only PSGallery exists
5858
$repos = Get-PSResourceRepository
59-
$repos.Count | Should -Be 1
59+
$repos.Count | Should -Be 2
6060
}
6161

6262
It "Reset repository store should support -WhatIf" {
@@ -65,14 +65,14 @@ Describe "Test Reset-PSResourceRepository" -tags 'CI' {
6565
$tmpDirPath = Join-Path -Path $TestDrive -ChildPath "tmpDir1"
6666
New-Item -ItemType Directory -Path $tmpDirPath -Force | Out-Null
6767
Register-PSResourceRepository -Name $TestRepoName -Uri $tmpDirPath
68-
68+
6969
# Capture repository count before WhatIf
7070
$reposBefore = Get-PSResourceRepository
7171
$countBefore = $reposBefore.Count
72-
72+
7373
# Act: Run with WhatIf
7474
Reset-PSResourceRepository -WhatIf
75-
75+
7676
# Assert: Repositories should not have changed
7777
$reposAfter = Get-PSResourceRepository
7878
$reposAfter.Count | Should -Be $countBefore
@@ -82,42 +82,42 @@ Describe "Test Reset-PSResourceRepository" -tags 'CI' {
8282
# Arrange: Corrupt the repository file
8383
$powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PSResourceGet"
8484
$repoFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml"
85-
85+
8686
# Write invalid XML to corrupt the file
8787
"This is not valid XML" | Set-Content -Path $repoFilePath -Force
88-
88+
8989
# Act: Reset the repository store
9090
$result = Reset-PSResourceRepository -Confirm:$false -PassThru
91-
91+
9292
# Assert: Should successfully reset and return PSGallery
9393
$result | Should -Not -BeNullOrEmpty
9494
$result.Name | Should -Be $PSGalleryName
95-
95+
9696
# Verify we can now read repositories
9797
$repos = Get-PSResourceRepository
98-
$repos.Count | Should -Be 1
98+
$repos.Count | Should -Be 2
9999
$repos.Name | Should -Be $PSGalleryName
100100
}
101101

102102
It "Reset repository store when file doesn't exist should succeed" {
103103
# Arrange: Delete the repository file
104104
$powerShellGetPath = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath "PSResourceGet"
105105
$repoFilePath = Join-Path -Path $powerShellGetPath -ChildPath "PSResourceRepository.xml"
106-
106+
107107
if (Test-Path -Path $repoFilePath) {
108108
Remove-Item -Path $repoFilePath -Force
109109
}
110-
110+
111111
# Act: Reset the repository store
112112
$result = Reset-PSResourceRepository -Confirm:$false -PassThru
113-
113+
114114
# Assert: Should successfully reset and return PSGallery
115115
$result | Should -Not -BeNullOrEmpty
116116
$result.Name | Should -Be $PSGalleryName
117-
117+
118118
# Verify PSGallery is registered
119119
$repos = Get-PSResourceRepository
120-
$repos.Count | Should -Be 1
120+
$repos.Count | Should -Be 2
121121
$repos.Name | Should -Be $PSGalleryName
122122
}
123123

@@ -129,21 +129,21 @@ Describe "Test Reset-PSResourceRepository" -tags 'CI' {
129129
New-Item -ItemType Directory -Path $tmpDir1Path -Force | Out-Null
130130
New-Item -ItemType Directory -Path $tmpDir2Path -Force | Out-Null
131131
New-Item -ItemType Directory -Path $tmpDir3Path -Force | Out-Null
132-
132+
133133
Register-PSResourceRepository -Name "testRepo1" -Uri $tmpDir1Path
134134
Register-PSResourceRepository -Name "testRepo2" -Uri $tmpDir2Path
135135
Register-PSResourceRepository -Name "testRepo3" -Uri $tmpDir3Path
136-
136+
137137
# Verify multiple repositories exist
138138
$reposBefore = Get-PSResourceRepository
139139
$reposBefore.Count | Should -BeGreaterThan 1
140-
140+
141141
# Act: Reset repository store
142142
Reset-PSResourceRepository -Confirm:$false
143-
143+
144144
# Assert: Only PSGallery should remain
145145
$reposAfter = Get-PSResourceRepository
146-
$reposAfter.Count | Should -Be 1
146+
$reposAfter.Count | Should -Be 2
147147
$reposAfter.Name | Should -Be $PSGalleryName
148148
}
149149
}

0 commit comments

Comments
 (0)