Skip to content

Commit 57e630f

Browse files
authored
Acr tests cleanup (#1590)
1 parent 3b117ac commit 57e630f

File tree

3 files changed

+73
-31
lines changed

3 files changed

+73
-31
lines changed

.ci/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ jobs:
9090
displayName: 'Set UsingAzAuth environment variable'
9191
condition: eq(${{ parameters.useAzAuth }}, true)
9292
93+
- task: AzurePowerShell@5
94+
inputs:
95+
azureSubscription: PSResourceGetACR
96+
azurePowerShellVersion: LatestVersion
97+
ScriptType: InlineScript
98+
inline: |
99+
$acrRepositoryNamesFolder = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath 'TempModules'
100+
Write-Verbose -Verbose "Creating new folder for acr repository names file to be placed with path: $acrRepositoryNamesFolder"
101+
$null = New-Item -Path $acrRepositoryNamesFolder -ItemType Directory
102+
$acrRepositoryNamesFilePath = Join-Path -Path $acrRepositoryNamesFolder -ChildPath 'ACRTestRepositoryNames.txt'
103+
New-Item -Path $acrRepositoryNamesFilePath
104+
displayName: 'Upload empty file for ACR functional tests to write test repository names to'
105+
93106
- task: AzurePowerShell@5
94107
inputs:
95108
azureSubscription: PSResourceGetACR
@@ -124,3 +137,20 @@ jobs:
124137
workingDirectory: ${{ parameters.buildDirectory }}
125138
errorActionPreference: continue
126139
condition: eq(${{ parameters.useAzAuth }}, false)
140+
141+
- task: AzurePowerShell@5
142+
inputs:
143+
azureSubscription: PSResourceGetACR
144+
azurePowerShellVersion: LatestVersion
145+
ScriptType: InlineScript
146+
inline: |
147+
$registryName = 'psresourcegettest'
148+
$acrRepositoryNamesFolder = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath 'TempModules'
149+
$acrRepositoryNamesFilePath = Join-Path -Path $acrRepositoryNamesFolder -ChildPath 'ACRTestRepositoryNames.txt'
150+
$repositoryNames = Get-Content -Path $acrRepositoryNamesFilePath
151+
foreach ($name in $repositoryNames)
152+
{
153+
# Delete images in the repository (including tags, unique layers, manifests) created for ACR tests
154+
Remove-AzContainerRegistryRepository -Name $name -RegistryName $registryName
155+
}
156+
displayName: 'Delete test repositories from ACR'

test/PSGetTestUtils.psm1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,3 +747,20 @@ function CheckForExpectedPSGetInfo
747747
$psGetInfo.UpdatedDate.Year | Should -BeExactly 1
748748
$psGetInfo.Version | Should -Be "1.1.0"
749749
}
750+
751+
function Set-TestACRRepositories
752+
{
753+
Param(
754+
[string[]]
755+
$repositoryNames
756+
)
757+
758+
$acrRepositoryNamesFolder = Join-Path -Path ([Environment]::GetFolderPath([System.Environment+SpecialFolder]::LocalApplicationData)) -ChildPath 'TempModules'
759+
$acrRepositoryNamesFilePath = Join-Path -Path $acrRepositoryNamesFolder -ChildPath 'ACRTestRepositoryNames.txt'
760+
$fileExists = Test-Path -Path $acrRepositoryNamesFilePath
761+
762+
if ($fileExists)
763+
{
764+
$repositoryNames | Out-File -FilePath $acrRepositoryNamesFilePath
765+
}
766+
}

test/PublishPSResourceTests/PublishPSResourceACRServer.Tests.ps1

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function CreateTestModule
88
{
99
param (
1010
[string] $Path = "$TestDrive",
11-
[string] $ModuleName = 'temp-psresourcegettemptestmodule'
11+
[string] $ModuleName = 'temp-testmodule'
1212
)
1313

1414
$modulePath = Join-Path -Path $Path -ChildPath $ModuleName
@@ -63,21 +63,18 @@ Describe "Test Publish-PSResource" -tags 'CI' {
6363

6464
# Create module
6565
$script:tmpModulesPath = Join-Path -Path $TestDrive -ChildPath "tmpModulesPath"
66-
$script:PublishModuleName = "temp-psresourcegettemptestmodule" + [System.Guid]::NewGuid();
66+
$script:PublishModuleName = "temp-testmodule" + [System.Guid]::NewGuid();
6767
$script:PublishModuleBase = Join-Path $script:tmpModulesPath -ChildPath $script:PublishModuleName
6868
if(!(Test-Path $script:PublishModuleBase))
6969
{
7070
New-Item -Path $script:PublishModuleBase -ItemType Directory -Force
7171
}
7272
$script:PublishModuleBaseUNC = $script:PublishModuleBase -Replace '^(.):', '\\localhost\$1$'
7373

74-
#Create dependency module
75-
$script:DependencyModuleName = "TEMP-PackageManagement"
76-
$script:DependencyModuleBase = Join-Path $script:tmpModulesPath -ChildPath $script:DependencyModuleName
77-
if(!(Test-Path $script:DependencyModuleBase))
78-
{
79-
New-Item -Path $script:DependencyModuleBase -ItemType Directory -Force
80-
}
74+
# create names of other modules and scripts that will be referenced in test
75+
$script:ModuleWithoutRequiredModuleName = "temp-testmodulewithoutrequiredmodule-" + [System.Guid]::NewGuid()
76+
$script:ScriptName = "temp-testscript" + [System.Guid]::NewGuid()
77+
$script:ScriptWithExternalDeps = "temp-testscriptwithexternaldeps" + [System.Guid]::NewGuid()
8178

8279
# Create temp destination path
8380
$script:destinationPath = [IO.Path]::GetFullPath((Join-Path -Path $TestDrive -ChildPath "tmpDestinationPath"))
@@ -107,19 +104,22 @@ Describe "Test Publish-PSResource" -tags 'CI' {
107104
}
108105
AfterAll {
109106
Get-RevertPSResourceRepositoryFile
107+
108+
# Note: all repository names provided as test packages for ACR, must have lower cased names, otherwise the Az cmdlets will not be able to properly find and delete it.
109+
$acrRepositoryNames = @($script:PublishModuleName, $script:ModuleWithoutRequiredModuleName, $script:ScriptName, $script:ScriptWithExternalDeps)
110+
Set-TestACRRepositories $acrRepositoryNames
110111
}
111112

112113
It "Publish module with required module not installed on the local machine using -SkipModuleManifestValidate" {
113-
$ModuleName = "modulewithmissingrequiredmodule-" + [System.Guid]::NewGuid()
114-
CreateTestModule -Path $TestDrive -ModuleName $ModuleName
114+
CreateTestModule -Path $TestDrive -ModuleName $script:ModuleWithoutRequiredModuleName
115115

116116
# Skip the module manifest validation test, which fails from the missing manifest required module.
117-
$testModulePath = Join-Path -Path $TestDrive -ChildPath $ModuleName
117+
$testModulePath = Join-Path -Path $TestDrive -ChildPath $script:ModuleWithoutRequiredModuleName
118118
Publish-PSResource -Path $testModulePath -Repository $ACRRepoName -Confirm:$false -SkipDependenciesCheck -SkipModuleManifestValidate
119119

120-
$results = Find-PSResource -Name $ModuleName -Repository $ACRRepoName
120+
$results = Find-PSResource -Name $script:ModuleWithoutRequiredModuleName -Repository $ACRRepoName
121121
$results | Should -Not -BeNullOrEmpty
122-
$results[0].Name | Should -Be $ModuleName
122+
$results[0].Name | Should -Be $script:ModuleWithoutRequiredModuleName
123123
$results[0].Version | Should -Be "1.0.0"
124124
}
125125

@@ -340,32 +340,29 @@ Describe "Test Publish-PSResource" -tags 'CI' {
340340
}
341341

342342
It "Publish a script"{
343-
$scriptBaseName = "temp-testscript"
344-
$scriptName = $scriptBaseName + [System.Guid]::NewGuid();
345343
$scriptVersion = "1.0.0"
346-
347344
$params = @{
348345
Version = $scriptVersion
349346
GUID = [guid]::NewGuid()
350347
Author = 'Jane'
351348
CompanyName = 'Microsoft Corporation'
352349
Copyright = '(c) 2024 Microsoft Corporation. All rights reserved.'
353-
Description = "Description for the $scriptBaseName script"
354-
LicenseUri = "https://$scriptBaseName.com/license"
355-
IconUri = "https://$scriptBaseName.com/icon"
356-
ProjectUri = "https://$scriptBaseName.com"
357-
Tags = @('Tag1','Tag2', "Tag-$scriptBaseName-$scriptVersion")
358-
ReleaseNotes = "$scriptBaseName release notes"
350+
Description = "Description for the $script:ScriptName script"
351+
LicenseUri = "https://$script:ScriptName.com/license"
352+
IconUri = "https://$script:ScriptName.com/icon"
353+
ProjectUri = "https://$script:ScriptName.com"
354+
Tags = @('Tag1','Tag2', "Tag-$script:ScriptName-$scriptVersion")
355+
ReleaseNotes = "$script:ScriptName release notes"
359356
}
360357

361-
$scriptPath = (Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$scriptName.ps1")
358+
$scriptPath = (Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$script:ScriptName.ps1")
362359
New-PSScriptFileInfo @params -Path $scriptPath
363360

364361
Publish-PSResource -Path $scriptPath -Repository $ACRRepoName
365362

366-
$results = Find-PSResource -Name $scriptName -Repository $ACRRepoName
363+
$results = Find-PSResource -Name $script:ScriptName -Repository $ACRRepoName
367364
$results | Should -Not -BeNullOrEmpty
368-
$results[0].Name | Should -Be $scriptName
365+
$results[0].Name | Should -Be $script:ScriptName
369366
$results[0].Version | Should -Be $scriptVersion
370367
}
371368

@@ -396,16 +393,15 @@ Describe "Test Publish-PSResource" -tags 'CI' {
396393
}
397394

398395
It "Should publish a script with ExternalModuleDependencies that are not published" {
399-
$scriptName = "ScriptWithExternalDependencies"
400396
$scriptVersion = "1.0.0"
401-
$scriptPath = Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1"
397+
$scriptPath = Join-Path -Path $script:tmpScriptsFolderPath -ChildPath "$script:ScriptWithExternalDeps.ps1"
402398
New-PSScriptFileInfo -Description 'test' -Version $scriptVersion -RequiredModules @{ModuleName='testModule'} -ExternalModuleDependencies 'testModule' -Path $scriptPath -Force
403399

404400
Publish-PSResource -Path $scriptPath -Repository $ACRRepoName
405401

406-
$results = Find-PSResource -Name $scriptName -Repository $ACRRepoName
402+
$results = Find-PSResource -Name $script:ScriptWithExternalDeps -Repository $ACRRepoName
407403
$results | Should -Not -BeNullOrEmpty
408-
$results[0].Name | Should -Be $scriptName
404+
$results[0].Name | Should -Be $script:ScriptWithExternalDeps
409405
$results[0].Version | Should -Be $scriptVersion
410406
}
411407

@@ -482,7 +478,6 @@ Describe "Test Publish-PSResource" -tags 'CI' {
482478
{ Publish-PSResource -Path $incorrectmoduleversion -Repository $ACRRepoName -ErrorAction Stop } | Should -Throw -ErrorId "InvalidModuleManifest,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource"
483479
}
484480

485-
486481
It "Publish a module with a dependency that has an invalid version format, should throw" {
487482
$moduleName = "incorrectdepmoduleversion"
488483
$incorrectdepmoduleversion = Join-Path -Path $script:testModulesFolderPath -ChildPath $moduleName

0 commit comments

Comments
 (0)