Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Tests/PSGalleryModule.Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,36 @@ Describe 'PSGalleryModule script' {
Should -Invoke -CommandName Install-Module -ModuleName PSDepend -Times 0
}
}

Context 'Multiple installed versions — requested version present but not the maximum' {
It 'Imports the requested version and skips Install when an older requested version is installed alongside a newer one' {
InModuleScope PSDepend {
Mock Get-Module {
@(
[PSCustomObject]@{ Name = 'TestModule'; Version = [version]'1.2.3' }
[PSCustomObject]@{ Name = 'TestModule'; Version = [version]'2.0.0' }
)
} -ParameterFilter { $ListAvailable }
}
$dep = New-PSDependFixture -DependencyName 'TestModule' -Version '1.2.3'
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -PSDependAction Test, Import
}
Should -Invoke -CommandName Import-PSDependModule -ModuleName PSDepend -Times 1 -Exactly `
-ParameterFilter { $Version.ToString() -eq '1.2.3' }
Should -Invoke -CommandName Install-Module -ModuleName PSDepend -Times 0
}
}

Context 'Repository = $null falls through to all registered repositories' {
It 'Skips repository validation and calls Install-Module without -Repository when Repository is null' {
$dep = New-PSDependFixture -DependencyName 'TestModule'
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -Repository $null
}
Should -Invoke -CommandName Get-PSRepository -ModuleName PSDepend -Times 0
Should -Invoke -CommandName Install-Module -ModuleName PSDepend -Times 1 -Exactly `
-ParameterFilter { -not $PSBoundParameters.ContainsKey('Repository') }
}
}
}
18 changes: 18 additions & 0 deletions Tests/PSResourceGet.Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,29 @@
$result | Should -Be $true
Should -Invoke -CommandName Install-PSResource -ModuleName PSDepend -Times 0
}

It 'Imports the requested version (not the maximum) when both are installed' {
InModuleScope PSDepend {
Mock Get-Module {
@(
[PSCustomObject]@{ Name = 'TestModule'; Version = [version]'1.2.3' }
[PSCustomObject]@{ Name = 'TestModule'; Version = [version]'2.0.0' }
)
} -ParameterFilter { $ListAvailable }
}
$dep = New-PSDependFixture -DependencyName 'TestModule' -DependencyType 'PSResourceGet' -Version '1.2.3'
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -PSDependAction Test, Import
}
Should -Invoke -CommandName Import-PSDependModule -ModuleName PSDepend -Times 1 -Exactly `
-ParameterFilter { $Version.ToString() -eq '1.2.3' }
Should -Invoke -CommandName Install-PSResource -ModuleName PSDepend -Times 0
}
}

Context 'Target as path uses Save-PSResource instead of Install-PSResource' {
It 'Calls Save-PSResource with -Path and skips Install-PSResource' {
$savePath = (New-Item 'TestDrive:/psresourceget-save' -ItemType Directory -Force).FullName

Check warning on line 220 in Tests/PSResourceGet.Type.Tests.ps1

View workflow job for this annotation

GitHub Actions / Continuous Integration / Run Linters

Unknown word (psresourceget) Suggestions: (presourcenet, presourceNet, preSourcenet, preSourceNet, Presourcenet)
$dep = New-PSDependFixture -DependencyName 'TestModule' -DependencyType 'PSResourceGet' -Target $savePath
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep
Expand Down
Loading