Skip to content

Commit 7f5987c

Browse files
Justin GroteJustin Grote
authored andcommitted
Cleanup Tests
1 parent 4d8741e commit 7f5987c

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

ModuleFast.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function Get-ModuleFastPlan {
111111
try {
112112
foreach ($moduleSpec in $ModulesToResolve) {
113113
$localMatch = Find-LocalModule $moduleSpec
114-
if ($localMatch) {
114+
if ($localMatch -and -not $Update) {
115115
Write-Verbose "Found local module $localMatch that satisfies $moduleSpec. Skipping..."
116116
#TODO: Capture this somewhere that we can use it to report in the deploy plan
117117
continue
@@ -338,7 +338,7 @@ function Get-ModuleFastPlan {
338338
# TODO: Figure out a way to dedupe this logic maybe recursively but I guess a function would be fine too
339339
foreach ($dependencySpec in $dependenciesToResolve) {
340340
$localMatch = Find-LocalModule $dependencySpec
341-
if ($localMatch) {
341+
if ($localMatch -and -not $Update) {
342342
Write-Verbose "Found local module $localMatch that satisfies dependency $dependencySpec. Skipping..."
343343
#TODO: Capture this somewhere that we can use it to report in the deploy plan
344344
continue
@@ -1079,7 +1079,11 @@ function Find-LocalModule {
10791079
# BUG: Prerelease Module paths are still not recognized by internal PS commands and can break things
10801080

10811081
# Search all psmodulepaths for the module
1082-
$modulePaths = $env:PSModulePath -split [Path]::PathSeparator
1082+
$modulePaths = $env:PSModulePath -split ([Path]::PathSeparator, [StringSplitOptions]::RemoveEmptyEntries)
1083+
if (-Not $modulePaths) {
1084+
Write-Warning 'No PSModulePaths found in $env:PSModulePath. If you are doing isolated testing you can disregard this.'
1085+
return
1086+
}
10831087

10841088
# NOTE: We are intentionally using return instead of continue here, as soon as we find a match we are done.
10851089
foreach ($modulePath in $modulePaths) {

ModuleFast.tests.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,21 @@ Describe 'Get-ModuleFastPlan' -Tag 'E2E' {
356356
}
357357

358358
Describe 'Install-ModuleFast' -Tag 'E2E' {
359+
BeforeEach {
360+
#Remove all PSModulePath to not affect existing environment
361+
$SCRIPT:__existingPSModulePath = $env:PSModulePath
362+
}
359363
It 'Installs Module' {
360-
Install-ModuleFast 'Az.Accounts'
364+
$env:PSModulePath = ''
365+
#HACK: The testdrive mount is not available in the threadjob runspaces so we need to translate it
366+
$testDrivePath = (Get-Item testdrive:).fullname
367+
Install-ModuleFast 'Az.Accounts' -Destination $testDrivePath
368+
Get-Item TestDrive:\Az.Accounts\*\Az.Accounts.psd1 | Should -Not -BeNullOrEmpty
361369
}
362370
It 'Installs Module with lots of dependencies (Az)' {
363-
Install-ModuleFast 'Az'
371+
Install-ModuleFast 'Az' -Destination (Get-Item testdrive:).fullname
372+
}
373+
AfterAll {
374+
$env:PSModulePath = $SCRIPT:__existingPSModulePath
364375
}
365376
}

0 commit comments

Comments
 (0)