Skip to content

Commit

Permalink
Merge pull request #74 from pspete/feature-VersionCompare
Browse files Browse the repository at this point in the history
Feature version compare
  • Loading branch information
pspete committed Jun 15, 2018
2 parents 7ccdbf9 + b2c536e commit f9b08b9
Show file tree
Hide file tree
Showing 70 changed files with 1,128 additions and 100 deletions.
4 changes: 4 additions & 0 deletions Tests/Add-PASAccountGroupMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Add-PASAccountGroupMember -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Approve-PASRequest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Approve-PASRequest -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
92 changes: 92 additions & 0 deletions Tests/Assert-VersionRequirement.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#Get Current Directory
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

#Get Function Name
$FunctionName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"

#Assume ModuleName from Repo Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf

#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"

#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"

if( -not (Get-Module -Name $ModuleName -All)) {

Import-Module -Name "$ManifestPath" -Force -ErrorAction Stop

}

Describe $FunctionName {

InModuleScope $ModuleName {

Context 'Minimum Version Met' {

It 'returns nothing if version requirment is satisfied' {
Assert-VersionRequirement -ExternalVersion "0.2" -RequiredVersion "0.1" | Should BeNullOrEmpty
}

It 'does not throw if version requirment is satisfied' {
{Assert-VersionRequirement -ExternalVersion "0.2" -RequiredVersion "0.1"} | Should Not Throw
}

}

Context 'Version Check Skipped' {

It 'returns nothing if external version is "0.0"' {
Assert-VersionRequirement -ExternalVersion "0.0" -RequiredVersion "9.9" | Should BeNullOrEmpty
}

It 'does not throw if external version is "0.0"' {
{Assert-VersionRequirement -ExternalVersion "0.0" -RequiredVersion "1.1"} | Should Not Throw
}

}

Context 'Minimum Version Not Met' {

Mock Get-ParentFunction -MockWith {
[PSCustomObject]@{
FunctionName = "SomeFunction"
ParameterSetName = "SomeParameterSet"
}
}
Function Test-Failure {Assert-VersionRequirement -ExternalVersion "1.1" -RequiredVersion "2.0"}

It 'throws error if external version is less than required version' {
{Test-Failure} | should Throw
}

It 'throws expected error if no custom parameterset has been used in the parent function' {

Mock Get-ParentFunction -MockWith {
[PSCustomObject]@{
FunctionName = "Test-Example"
ParameterSetName = "__AllParameterSets"
}
}

{Test-Failure} | should Throw "CyberArk 1.1 does not meet the minimum version requirement of 2.0 for Test-Example (using ParameterSet: __AllParameterSets)"
}

It 'throws expected error if a custom parameterset has been used in the parent function' {
Mock Get-ParentFunction -MockWith {
[PSCustomObject]@{
FunctionName = "Test-Example"
ParameterSetName = "SomeParamSet"
}
}
{Test-Failure} | should Throw "CyberArk 1.1 does not meet the minimum version requirement of 2.0 for Test-Example (using ParameterSet: SomeParamSet)"
}
}




}

}
44 changes: 44 additions & 0 deletions Tests/Compare-MinimumVersion.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#Get Current Directory
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

#Get Function Name
$FunctionName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"

#Assume ModuleName from Repo Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf

#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"

#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"

if( -not (Get-Module -Name $ModuleName -All)) {

Import-Module -Name "$ManifestPath" -Force -ErrorAction Stop

}

Describe $FunctionName {

InModuleScope $ModuleName {

It 'returns TRUE if version is greater than minimum version' {
Compare-MinimumVersion -Version "9.8.0" -MinimumVersion "8.9.0" | Should Be $true
}

It 'returns FALSE if version is less than minimum version' {
Compare-MinimumVersion -Version "9.8.0" -MinimumVersion "9.9.0" | Should Be $false
}

It 'returns TRUE if version is 0.0' {

Compare-MinimumVersion -Version "0.0" -MinimumVersion "1.1.0" | Should Be $true

}



}

}
4 changes: 4 additions & 0 deletions Tests/Deny-PASRequest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Deny-PASRequest -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASAccountGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASAccountGroup -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASAccountGroupMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASAccountGroupMember -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
5 changes: 5 additions & 0 deletions Tests/Get-PASAccountPassword.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ Describe $FunctionName {
}


It "throws error if version requirement not met" {
{$InputObj | Get-PASAccountPassword -UseV10API -Reason "SomeReason" -TicketingSystemName "someSystem" -TicketId 12345 -ExternalVersion "1.0"} | Should Throw
}


}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASComponentDetail.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASComponentDetail -ComponentID PVWA -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASComponentSummary.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASComponentSummary -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASOnboardingRule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASOnboardingRule -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
8 changes: 8 additions & 0 deletions Tests/Get-PASPSMConnectionParameter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ Describe $FunctionName {

}

It "throws error if version requirement not met for RDP connection method" {
{$InputObj | Get-PASPSMConnectionParameter -ConnectionMethod RDP -ExternalVersion "9.8"} | Should Throw
}

It "throws error if version requirement not met for PSMGW connection method" {
{$InputObj | Get-PASPSMConnectionParameter -ConnectionMethod PSMGW -ExternalVersion "9.10"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASPSMRecording.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASPSMRecording -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASPSMSession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASPSMSession -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASPlatform.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASPlatform -ExternalVersion "1.0"} | Should Throw
}

}

Context "Output" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASRequest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASRequest -RequestType MyRequests -OnlyWaiting $true -Expired $true -ExternalVersion "1.0"} | Should Throw
}

}

Context "Input - IncomingRequests" {
Expand Down
4 changes: 4 additions & 0 deletions Tests/Get-PASRequestDetail.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Get-PASRequestDetail -RequestType MyRequests -ExternalVersion "1.0"} | Should Throw
}

}

Context "Input - IncomingRequests" {
Expand Down
64 changes: 64 additions & 0 deletions Tests/Get-ParentFunction.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#Get Current Directory
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

#Get Function Name
$FunctionName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"

#Assume ModuleName from Repo Root folder
$ModuleName = Split-Path (Split-Path $Here -Parent) -Leaf

#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"

#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"

if( -not (Get-Module -Name $ModuleName -All)) {

Import-Module -Name "$ManifestPath" -Force -ErrorAction Stop

}

Describe $FunctionName {

InModuleScope $ModuleName {

It 'returns parent function name' {
Function Test-Parent {Test-Child}
Function Test-Child {Get-ParentFunction}
$ThisTest = Test-Parent

$ThisTest.FunctionName | Should Be Test-Parent
}

It 'returns expected parent function name from expected scope' {
Function Test-Example {
[CmdletBinding()]
param([parameter(ParameterSetName = "ExampleParamSet")][string]$Name)
Test-Parent
}
Function Test-Parent {Test-Child}
Function Test-Child {Get-ParentFunction -Scope 3}
$ThisTest = Test-Example -Name "test"

$ThisTest.FunctionName | Should Be "Test-Example"

}

It 'returns expected ParameterSetName from expected scope' {
Function Test-Example {
[CmdletBinding()]
param([parameter(ParameterSetName = "ExampleParamSet")][string]$Name)
Test-Parent
}
Function Test-Parent {Test-Child}
Function Test-Child {Get-ParentFunction -Scope 3}
$ThisTest = Test-Example -Name "test"

$ThisTest.ParameterSetName | Should Be "ExampleParamSet"
}


}

}
3 changes: 3 additions & 0 deletions Tests/Import-PASConnectionComponent.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Import-PASConnectionComponent -ImportFile $($file.name) -ExternalVersion "1.0"} | Should Throw
}

}

Expand Down
4 changes: 4 additions & 0 deletions Tests/Import-PASPlatform.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ Describe $FunctionName {

}

It "throws error if version requirement not met" {
{$InputObj | Import-PASPlatform -ImportFile $($file.name) -ExternalVersion "1.0"} | Should Throw
}


}

Expand Down

0 comments on commit f9b08b9

Please sign in to comment.