I'm attempting (and failing) to run a data-driven Pester v5 test over a PS Class. In the Tests/ directory are the 3 (currently failing) implemetations.
Last active
July 7, 2022 16:07
-
-
Save petervandivier/794fc652539e8834839f9629c512898a to your computer and use it in GitHub Desktop.
Pester PS Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using namespace System.Management.Automation | |
| class foo : IValidateSetValuesGenerator { | |
| [string[]] GetValidValues() { | |
| $Values = @( | |
| 'foo' | |
| 'bar' | |
| 'baz' | |
| ) | |
| return $Values | |
| } | |
| } | |
| # class fooCollection { | |
| # [foo[]]$Collection | |
| # } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @{ | |
| RootModule = '.\foo.psm1' | |
| ModuleVersion = '0.0' | |
| VariablesToExport = @( | |
| 'FooHash' | |
| ) | |
| FunctionsToExport = @( | |
| 'Get-Foo' | |
| ) | |
| ScriptsToProcess = @( | |
| 'Classes/classes.ps1' | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Push-Location $PSScriptRoot | |
| . ./Functions/Get-Foo.ps1 | |
| $global:FooHash = @{ | |
| foo = @{} | |
| bar = @{} | |
| baz = @{} | |
| } | |
| Export-ModuleMember -Variable FooHash | |
| Pop-Location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-Foo { | |
| [CmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory)] | |
| [ValidateSet([foo])] | |
| [string]$Name | |
| ) | |
| $Name | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Requires -Modules foo | |
| Push-Location $PSScriptRoot | |
| BeforeAll { | |
| . ./../Classes/foo.ps1 | |
| } | |
| Describe "FooHash should contain all of type [foo]" { | |
| It "<_>" -ForEach ($FooHash.GetEnumerator().Name | Sort-Object) { | |
| $_ | Should -BeIn ([foo]::New().GetValidValues()) | |
| } | |
| } | |
| Describe "[foo] should be fully enumerated in `$FooHash" { | |
| It "<_>" -ForEach ([foo]::New().GetValidValues() | Sort-Object) { | |
| $FooHash.GetEnumerator().Name | Should -Contain $_ | |
| } | |
| } | |
| Pop-Location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Requires -Modules foo | |
| Push-Location $PSScriptRoot | |
| BeforeAll { | |
| . ./../Classes/foo.ps1 | |
| } | |
| Describe "FooHash should contain all of type [foo]" { | |
| It "<_>" -ForEach ($FooHash.GetEnumerator().Name | Sort-Object) { | |
| $_ | Should -BeIn ([foo]::New().GetValidValues()) | |
| } | |
| } | |
| Describe "[foo] should be fully enumerated in `$FooHash" { | |
| It "<_>" -ForEach ([foo]::New().GetValidValues() | Sort-Object) { | |
| $FooHash.GetEnumerator().Name | Should -Contain $_ | |
| } | |
| } | |
| Pop-Location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Requires -Modules foo | |
| BeforeAll { | |
| $module = @{ | |
| ModuleName = 'foo' | |
| } | |
| } | |
| InModuleScope @module { | |
| Describe "FooHash should contain all of type [foo]" { | |
| It "<_>" -ForEach ($FooHash.GetEnumerator().Name | Sort-Object) { | |
| $_ | Should -BeIn ([foo]::New().GetValidValues()) | |
| } | |
| } | |
| Describe "[foo] should be fully enumerated in `$FooHash" { | |
| It "<_>" -ForEach ([foo]::New().GetValidValues() | Sort-Object) { | |
| $FooHash.GetEnumerator().Name | Should -Contain $_ | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment