@@ -8,7 +8,7 @@ function CreateTestModule
8
8
{
9
9
param (
10
10
[string ] $Path = " $TestDrive " ,
11
- [string ] $ModuleName = ' temp-psresourcegettemptestmodule '
11
+ [string ] $ModuleName = ' temp-testmodule '
12
12
)
13
13
14
14
$modulePath = Join-Path - Path $Path - ChildPath $ModuleName
@@ -63,21 +63,18 @@ Describe "Test Publish-PSResource" -tags 'CI' {
63
63
64
64
# Create module
65
65
$script :tmpModulesPath = Join-Path - Path $TestDrive - ChildPath " tmpModulesPath"
66
- $script :PublishModuleName = " temp-psresourcegettemptestmodule " + [System.Guid ]::NewGuid();
66
+ $script :PublishModuleName = " temp-testmodule " + [System.Guid ]::NewGuid();
67
67
$script :PublishModuleBase = Join-Path $script :tmpModulesPath - ChildPath $script :PublishModuleName
68
68
if (! (Test-Path $script :PublishModuleBase ))
69
69
{
70
70
New-Item - Path $script :PublishModuleBase - ItemType Directory - Force
71
71
}
72
72
$script :PublishModuleBaseUNC = $script :PublishModuleBase -Replace ' ^(.):' , ' \\localhost\$1$'
73
73
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()
81
78
82
79
# Create temp destination path
83
80
$script :destinationPath = [IO.Path ]::GetFullPath((Join-Path - Path $TestDrive - ChildPath " tmpDestinationPath" ))
@@ -107,19 +104,22 @@ Describe "Test Publish-PSResource" -tags 'CI' {
107
104
}
108
105
AfterAll {
109
106
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
110
111
}
111
112
112
113
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
115
115
116
116
# 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
118
118
Publish-PSResource - Path $testModulePath - Repository $ACRRepoName - Confirm:$false - SkipDependenciesCheck - SkipModuleManifestValidate
119
119
120
- $results = Find-PSResource - Name $ModuleName - Repository $ACRRepoName
120
+ $results = Find-PSResource - Name $script :ModuleWithoutRequiredModuleName - Repository $ACRRepoName
121
121
$results | Should -Not - BeNullOrEmpty
122
- $results [0 ].Name | Should - Be $ModuleName
122
+ $results [0 ].Name | Should - Be $script :ModuleWithoutRequiredModuleName
123
123
$results [0 ].Version | Should - Be " 1.0.0"
124
124
}
125
125
@@ -340,32 +340,29 @@ Describe "Test Publish-PSResource" -tags 'CI' {
340
340
}
341
341
342
342
It " Publish a script" {
343
- $scriptBaseName = " temp-testscript"
344
- $scriptName = $scriptBaseName + [System.Guid ]::NewGuid();
345
343
$scriptVersion = " 1.0.0"
346
-
347
344
$params = @ {
348
345
Version = $scriptVersion
349
346
GUID = [guid ]::NewGuid()
350
347
Author = ' Jane'
351
348
CompanyName = ' Microsoft Corporation'
352
349
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"
359
356
}
360
357
361
- $scriptPath = (Join-Path - Path $script :tmpScriptsFolderPath - ChildPath " $scriptName .ps1" )
358
+ $scriptPath = (Join-Path - Path $script :tmpScriptsFolderPath - ChildPath " $script :ScriptName .ps1" )
362
359
New-PSScriptFileInfo @params - Path $scriptPath
363
360
364
361
Publish-PSResource - Path $scriptPath - Repository $ACRRepoName
365
362
366
- $results = Find-PSResource - Name $scriptName - Repository $ACRRepoName
363
+ $results = Find-PSResource - Name $script :ScriptName - Repository $ACRRepoName
367
364
$results | Should -Not - BeNullOrEmpty
368
- $results [0 ].Name | Should - Be $scriptName
365
+ $results [0 ].Name | Should - Be $script :ScriptName
369
366
$results [0 ].Version | Should - Be $scriptVersion
370
367
}
371
368
@@ -396,16 +393,15 @@ Describe "Test Publish-PSResource" -tags 'CI' {
396
393
}
397
394
398
395
It " Should publish a script with ExternalModuleDependencies that are not published" {
399
- $scriptName = " ScriptWithExternalDependencies"
400
396
$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"
402
398
New-PSScriptFileInfo - Description ' test' - Version $scriptVersion - RequiredModules @ {ModuleName = ' testModule' } - ExternalModuleDependencies ' testModule' - Path $scriptPath - Force
403
399
404
400
Publish-PSResource - Path $scriptPath - Repository $ACRRepoName
405
401
406
- $results = Find-PSResource - Name $scriptName - Repository $ACRRepoName
402
+ $results = Find-PSResource - Name $script :ScriptWithExternalDeps - Repository $ACRRepoName
407
403
$results | Should -Not - BeNullOrEmpty
408
- $results [0 ].Name | Should - Be $scriptName
404
+ $results [0 ].Name | Should - Be $script :ScriptWithExternalDeps
409
405
$results [0 ].Version | Should - Be $scriptVersion
410
406
}
411
407
@@ -482,7 +478,6 @@ Describe "Test Publish-PSResource" -tags 'CI' {
482
478
{ Publish-PSResource - Path $incorrectmoduleversion - Repository $ACRRepoName - ErrorAction Stop } | Should - Throw - ErrorId " InvalidModuleManifest,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource"
483
479
}
484
480
485
-
486
481
It " Publish a module with a dependency that has an invalid version format, should throw" {
487
482
$moduleName = " incorrectdepmoduleversion"
488
483
$incorrectdepmoduleversion = Join-Path - Path $script :testModulesFolderPath - ChildPath $moduleName
0 commit comments