Skip to content

Commit

Permalink
Adding test for sematic version
Browse files Browse the repository at this point in the history
  • Loading branch information
raandree committed Jun 26, 2020
1 parent 2255726 commit efe2c7b
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 13 deletions.
8 changes: 8 additions & 0 deletions Tests/DependFiles/psgallerymodule.AllowPrerelease.depend.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@{
'imaginary' = @{
Version = '1.2.5'
Parameters = @{
AllowPrerelease = $true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
'imaginary' = @{
Version = '1.2.5-preview0002'
}
}
153 changes: 140 additions & 13 deletions Tests/PSModuleGallery.Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ InModuleScope 'PSDepend' {
}
}


Context 'Saves Modules' {
Mock Save-Module { Return $true }

Expand Down Expand Up @@ -106,7 +105,6 @@ InModuleScope 'PSDepend' {
}
}


Context 'Repository does not Exist' {
Mock Install-Module { throw "Unable to find repository 'Blah'" } -ParameterFilter { $Repository -eq 'Blah'}

Expand All @@ -116,7 +114,7 @@ InModuleScope 'PSDepend' {
}
}

Context 'Same module version exists' {
Context 'Same module version exists (Version)' {
Mock Install-Module {}
Mock Get-Module {
[pscustomobject]@{
Expand All @@ -134,7 +132,25 @@ InModuleScope 'PSDepend' {
}
}

Context 'Latest module required, and already installed' {
Context 'Same module version exists (SemVersion)' {
Mock Install-Module {}
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}
Mock Find-Module

It 'Skips Install-Module' {
Invoke-PSDepend @Verbose -Path "$TestDepends/psgallerymodule.SameSemanticVersion.depend.psd1" -Force -ErrorAction Stop

Assert-MockCalled Get-Module -Times 1 -Exactly
Assert-MockCalled Find-Module -Times 0 -Exactly
Assert-MockCalled Install-Module -Times 0 -Exactly
}
}

Context 'Latest module required, and already installed (version)' {
Mock Install-Module {}
Mock Get-Module {
[pscustomobject]@{
Expand All @@ -156,14 +172,36 @@ InModuleScope 'PSDepend' {
}
}

Context 'Latest module required, and already installed (SemVersion)' {
Mock Install-Module {}
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}
Mock Find-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}

It 'Skips Install-Module' {
Invoke-PSDepend @Verbose -Path "$TestDepends/psgallerymodule.latestversion.depend.psd1" -Force -ErrorAction Stop

Assert-MockCalled Get-Module -Times 1 -Exactly
Assert-MockCalled Find-Module -Times 1 -Exactly
Assert-MockCalled Install-Module -Times 0 -Exactly
}
}

Context 'Test-Dependency' {

BeforeEach {
Mock Install-Module {}
Mock Find-Module {}
}

It 'Returns $true when it finds an existing module' {
It 'Returns $true when it finds an existing module (Version)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5'
Expand All @@ -175,7 +213,19 @@ InModuleScope 'PSDepend' {
$Results[0] | Should be $True
}

It 'Returns $true when it finds an existing latest module' {
It 'Returns $true when it finds an existing module (SemVersion)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.SameSemanticVersion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $True
}

It 'Returns $true when it finds an existing latest module (Version)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5'
Expand All @@ -192,14 +242,40 @@ InModuleScope 'PSDepend' {
$Results[0] | Should be $True
}

It "Returns `$false when it doesn't find an existing module" {
It 'Returns $true when it finds an existing latest module (SemVersion)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}
Mock Find-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.latestversion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $True
}

It "Returns `$false when it doesn't find an existing module (Version)" {
Mock Get-Module { $null }
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.sameversion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $False
}
It "Returns `$false when it finds an existing module with a lower version" {

It "Returns `$false when it doesn't find an existing module (SemVersion)" {
Mock Get-Module { $null }
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.SameSemanticVersion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $False
}

It "Returns `$false when it finds an existing module with a lower version (Version)" {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.4'
Expand All @@ -211,7 +287,31 @@ InModuleScope 'PSDepend' {
$Results[0] | Should be $False
}

It "Returns `$false when it finds an existing module with a lower version than latest" {
It 'Returns $false when it finds an existing module with a lower version (SemVersion)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5-preview0001'
}
}
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.SameSemanticVersion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $False
}

It 'Returns $false when it finds an existing module with a lower version (SemVersion-Version)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.4'
}
}
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.SameSemanticVersion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $False
}

It 'Returns $false when it finds an existing module with a lower version than latest (Version)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.4'
Expand All @@ -227,6 +327,23 @@ InModuleScope 'PSDepend' {
$Results.Count | Should be 1
$Results[0] | Should be $False
}

It 'Returns $false when it finds an existing module with a lower version than latest (SemVersion)' {
Mock Get-Module {
[pscustomobject]@{
Version = '1.2.5-preview0001'
}
}
Mock Find-Module {
[pscustomobject]@{
Version = '1.2.5-preview0002'
}
}
$Results = @( Get-Dependency @Verbose -Path "$TestDepends/psgallerymodule.latestversion.depend.psd1" |
Test-Dependency -Quiet )
$Results.Count | Should be 1
$Results[0] | Should be $False
}
}

Context 'Imports dependencies' {
Expand Down Expand Up @@ -292,9 +409,9 @@ InModuleScope 'PSDepend' {
($env:PSModulePath -split ([IO.Path]::PathSeparator)) -contains $SavePath | Should Be $True
}
}

#>
Context 'SkipPublisherCheck' {
It 'Supplies switch to Install-Module' {
It 'Supplies SkipPublisherCheck switch to Install-Module' {
Mock Get-PSRepository { Return $true }
Mock Install-Module {}
Invoke-PSDepend @Verbose -Path "$TestDepends\psgallerymodule.skippubcheck.depend.psd1" -Force -ErrorAction Stop
Expand All @@ -303,6 +420,17 @@ InModuleScope 'PSDepend' {
}
}
}

Context 'AllowPrerelease' {
It 'Supplies AllowPrerelease switch to Install-Module' {
Mock Get-PSRepository { Return $true }
Mock Install-Module {}
Invoke-PSDepend @Verbose -Path "$TestDepends\psgallerymodule.AllowPrerelease.depend.psd1" -Force -ErrorAction Stop
Assert-MockCalled -CommandName Install-Module -Times 1 -Exactly -ExclusiveFilter {
$AllowPrerelease -eq $true
}
}
}
}

Describe "Git Type PS$PSVersion" -Tag "WindowsOnly" {
Expand Down Expand Up @@ -338,6 +466,7 @@ InModuleScope 'PSDepend' {
}

}

Context 'Tests dependency' {
Mock New-Item { return $true }
Mock Push-Location {}
Expand Down Expand Up @@ -704,7 +833,6 @@ InModuleScope 'PSDepend' {
}
}
#>

Context 'PackageSource does not Exist' {
Mock Install-Package
Mock Get-PackageSource
Expand Down Expand Up @@ -755,7 +883,6 @@ InModuleScope 'PSDepend' {
#>


function Install-Package {[cmdletbinding()]param( $Source, $Name, $RequiredVersion, $Force)}
function Get-PackageSource { @([pscustomobject]@{Name = 'chocolatey'; ProviderName = 'chocolatey'}) }

Expand Down

0 comments on commit efe2c7b

Please sign in to comment.