@@ -213,175 +213,6 @@ Describe 'Registering an Azure Artifacts PS Repository' {
213213 }
214214}
215215
216- # Describe 'Importing a PowerShell module from Azure Artifacts' {
217- # It 'Should import the module properly' {
218- # # Arrange.
219- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
220- # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository }
221- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
222-
223- # # Act and Assert.
224- # $action | Should -Not -Throw
225- # Get-Module -Name $PowerShellModuleName | Should -Not -BeNullOrEmpty
226- # }
227-
228- # It 'Should import the module properly when forced' {
229- # # Arrange.
230- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
231- # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Force }
232- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
233-
234- # # Act and Assert.
235- # $action | Should -Not -Throw
236- # Get-Module -Name $PowerShellModuleName | Should -Not -BeNullOrEmpty
237- # }
238-
239- # It 'Should import the module properly when a specific version is requested' {
240- # # Arrange.
241- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
242- # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Version $ValidOlderModuleVersionThatExists }
243- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
244-
245- # # Act and Assert.
246- # $action | Should -Not -Throw
247- # $module = Get-Module -Name $PowerShellModuleName
248- # $module | Should -Not -BeNullOrEmpty
249- # $module.Version | Should -Be $ValidOlderModuleVersionThatExists
250- # }
251-
252- # # Could not get this one to work, as it complains that the module is in use so it's not able to uninstall it to do a proper test.
253- # # It 'Should throw an error when trying to import a version that does not exist and no different version exists' {
254- # # # Arrange.
255- # # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
256- # # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Version $InvalidModuleVersionThatDoesNotExist }
257- # # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
258- # # Uninstall-Module -Name $PowerShellModuleName -Force -AllVersions
259- # # Write-Host "Versions: " + (Get-Module -Name $PowerShellModuleName -ListAvailable | Format-Table | Out-String)
260- # # Get-Module -Name $PowerShellModuleName -ListAvailable | Should -BeNullOrEmpty
261-
262- # # # Act and Assert.
263- # # $action | Should -Not -Throw
264- # # }
265-
266- # It 'Should write an error and continue when trying to import a version that does not exist, but a different version exists' {
267- # # Arrange.
268- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
269- # Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository
270- # Get-Module -Name $PowerShellModuleName -ListAvailable | Should -Not -BeNullOrEmpty
271-
272- # # Act
273- # Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Version $InvalidModuleVersionThatDoesNotExist -ErrorAction SilentlyContinue -ErrorVariable err
274-
275- # # Assert.
276- # $err.Count | Should -BeGreaterThan 0
277- # [string] $errors = $err | ForEach-Object { $_.ToString() }
278- # $errors | Should -Match 'is already installed and will be imported instead.'
279- # }
280-
281- # It 'Should throw an error when trying to import a module that does not exist' {
282- # # Arrange.
283- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
284- # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name 'InvalidModuleName' -Repository $repository }
285-
286- # # Act and Assert.
287- # $action | Should -Throw "The PowerShell module 'InvalidModuleName' could not be found in the PSRepository"
288- # }
289-
290- # It 'Should write an error and continue when an invalid Repository is specified, but the module is already installed' {
291- # # Arrange.
292- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
293- # Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository
294- # Get-Module -Name $PowerShellModuleName -ListAvailable | Should -Not -BeNullOrEmpty
295-
296- # # Act.
297- # Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository 'InvalidRepositoryName' -ErrorAction SilentlyContinue -ErrorVariable err
298-
299- # # Act and Assert.
300- # $err.Count | Should -BeGreaterThan 0
301- # [string] $errors = $err | ForEach-Object { $_.ToString() }
302- # $errors | Should -Match "Version '.+?' is installed on computer '.+?' though so it will be used.*"
303- # }
304-
305- # It 'Should throw an error if the Credential is invalid' {
306- # # Arrange.
307- # [System.Security.SecureString] $invalidPat = 'InvalidPat' | ConvertTo-SecureString -AsPlainText -Force
308- # [PSCredential] $invalidCredential = New-Object System.Management.Automation.PSCredential 'Username@DoesNotMatter.com', $invalidPat
309- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
310-
311- # # Act.
312- # Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Credential $invalidCredential -ErrorAction SilentlyContinue -ErrorVariable err
313-
314- # # Assert.
315- # $err.Count | Should -BeGreaterThan 0
316- # [string] $errors = $err | ForEach-Object { $_.ToString() }
317- # $errors | Should -Match "Perhaps the credentials used are not valid."
318- # }
319-
320- # It 'Should not import module Prerelease versions when the Prerelease switch is not provided' {
321- # # Arrange.
322- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
323- # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Version $ValidModulePrereleaseVersionThatExists }
324- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
325-
326- # # Act and Assert.
327- # $action | Should -Throw "The '-AllowPrerelease' parameter must be specified when using the Prerelease string"
328- # Get-Module -Name $PowerShellModuleName | Should -BeNullOrEmpty
329- # }
330-
331- # It 'Should import module Prerelease versions properly' {
332- # # Arrange.
333- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
334- # [ScriptBlock] $action = { Import-AzureArtifactsModule -Name $PowerShellModuleName -Repository $repository -Version $ValidModulePrereleaseVersionThatExists -AllowPrerelease }
335- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
336-
337- # # PowerShell is weird about the way it supports prerelease versions.
338- # # The directory it installs to and the version it gives it is just the version with the prerelease portion removed.
339- # # So we need to strip off the prerelease portion of the version number. i.e. what comes after the hyphen.
340- # [string] $prereleaseVersionsStablePortion = ($ValidModulePrereleaseVersionThatExists -split '-')[0]
341-
342- # # Act and Assert.
343- # $action | Should -Not -Throw
344- # $module = Get-Module -Name $PowerShellModuleName
345- # $module | Should -Not -BeNullOrEmpty
346- # $module.Version | Should -Be $prereleaseVersionsStablePortion
347- # }
348-
349- # It 'Should import the module properly when piping in the Repository Name' {
350- # # Arrange.
351- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
352- # [ScriptBlock] $action = {
353- # $repository | Import-AzureArtifactsModule -Name $PowerShellModuleName
354- # }
355- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
356-
357- # # Act and Assert.
358- # $action | Should -Not -Throw
359- # Get-Module -Name $PowerShellModuleName | Should -Not -BeNullOrEmpty
360- # }
361-
362- # It 'Should import the module properly when piping in all of the parameters by property name' {
363- # # Arrange.
364- # [string] $repository = Register-AzureArtifactsPSRepository -FeedUrl $FeedUrl
365- # [PSCustomObject] $params = [PSCustomObject]@{
366- # Name = $PowerShellModuleName
367- # Version = $null
368- # AllowPrerelease = $false
369- # Repository = $repository
370- # Credential = $Credential
371- # Force = $false
372- # Scope = 'CurrentUser'
373- # }
374- # [ScriptBlock] $action = {
375- # $params | Import-AzureArtifactsModule
376- # }
377- # Remove-PowerShellModule -powerShellModuleName $PowerShellModuleName
378-
379- # # Act and Assert.
380- # $action | Should -Not -Throw
381- # Get-Module -Name $PowerShellModuleName | Should -Not -BeNullOrEmpty
382- # }
383- # }
384-
385216Describe ' Finding a PowerShell module from Azure Artifacts' {
386217 Context ' When relying on retrieving the Azure Artifacts PAT from the environment variable that exists' {
387218 Mock Get-SecurePersonalAccessTokenFromEnvironmentVariable { return $SecurePersonalAccessToken } - ModuleName $ModuleNameBeingTested
0 commit comments