|
1 | | -try { |
2 | | - $enlistmentRoot = git rev-parse --show-toplevel |
3 | | - |
4 | | - $docLocation = [io.path]::Combine($enlistmentRoot, "docs","cmdlet-example") |
5 | | - Push-Location $docLocation |
6 | | - ./SendGreeting.Tests.ps1 |
7 | | -} finally { |
8 | | - Pop-Location |
| 1 | +# Looking at pester internal to get tag filter and ExcludeTagFilter |
| 2 | +# This seems like the most stable way to do this |
| 3 | +# other options like testing for tags seems more likely to break |
| 4 | + |
| 5 | +InModuleScope Pester { |
| 6 | + Describe 'Getting Tag Filters' -Tag CI { |
| 7 | + $global:__PesterTags = $pester.TagFilter |
| 8 | + $global:__PesterExcludeTags = $pester.ExcludeTagFilter |
| 9 | + } |
| 10 | +} |
| 11 | +Describe 'SDK Send Greeting Sample Tests' -Tag CI { |
| 12 | + |
| 13 | + try { |
| 14 | + $enlistmentRoot = git rev-parse --show-toplevel |
| 15 | + $docLocation = Join-Path -Path $enlistmentRoot -ChildPath '\docs\cmdlet-example' |
| 16 | + $testResultPath = Join-Path $TestDrive 'sendgreetingresults.xml' |
| 17 | + $sampleCopy = Join-Path $TestDrive 'sendgreeting' |
| 18 | + $fullSampleCopyPath = Join-Path $sampleCopy 'cmdlet-example' |
| 19 | + $powershell = (Get-Process -id $PID).MainModule.FileName |
| 20 | + if(!(Test-Path $sampleCopy)) |
| 21 | + { |
| 22 | + New-Item -ItemType Directory -Path $sampleCopy |
| 23 | + } |
| 24 | + |
| 25 | + Copy-Item -Recurse -Path $docLocation -Destination $sampleCopy -Force |
| 26 | + Get-ChildItem -Recurse $sampleCopy | %{ Write-Verbose "sc: $($_.FullName)"} |
| 27 | + |
| 28 | + $pesterCommand = "Invoke-Pester $sampleCopy -PassThru" |
| 29 | + if($global:__PesterTags) |
| 30 | + { |
| 31 | + $pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')" |
| 32 | + } |
| 33 | + |
| 34 | + if($global:__PesterExcludeTags) |
| 35 | + { |
| 36 | + $pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')" |
| 37 | + } |
| 38 | + |
| 39 | + $importPesterCommand = 'Import-module Pester' |
| 40 | + if($isCore) |
| 41 | + { |
| 42 | + $importPesterCommand = "Import-Module $(Join-Path -path $PSHOME -child '/Modules/Pester')" |
| 43 | + } |
| 44 | + |
| 45 | + $command = @" |
| 46 | +Push-Location -Path $fullSampleCopyPath |
| 47 | +$importPesterCommand |
| 48 | +$pesterCommand | Export-Clixml -Path $testResultPath |
| 49 | +"@ |
| 50 | + |
| 51 | + Write-Verbose -Message "command: '$command'" |
| 52 | + $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) |
| 53 | + $encodedCommand = [Convert]::ToBase64String($bytes) |
| 54 | + &$powershell -encodedCommand $encodedCommand |
| 55 | + |
| 56 | + it "Should have test results file" { |
| 57 | + $testResultPath | should exist |
| 58 | + $script:results = Import-Clixml $testResultPath |
| 59 | + } |
| 60 | + |
| 61 | + it "Should have test results" { |
| 62 | + $script:results | should not be BeNullOrEmpty |
| 63 | + $script:results.TotalCount | should not BeNullOrEmpty |
| 64 | + $script:results.TestResult.Count | should not BeNullOrEmpty |
| 65 | + } |
| 66 | + |
| 67 | + it "Should have no failures" { |
| 68 | + $script:results.FailedCount | should be 0 |
| 69 | + } |
| 70 | + |
| 71 | + foreach($testResult in $script:results.TestResult){ |
| 72 | + Context "Test $($testResult.Name)" { |
| 73 | + it "should have no failure message" { |
| 74 | + $testResult.FailureMessage | should BeNullOrEmpty |
| 75 | + } |
| 76 | + it "should have no stack trace" { |
| 77 | + $testResult.StackTrace | should BeNullOrEmpty |
| 78 | + } |
| 79 | + it "should have no error record" { |
| 80 | + $testResult.ErrorRecord | should BeNullOrEmpty |
| 81 | + } |
| 82 | + it "should have not failed" { |
| 83 | + Write-Verbose "Result: $($testResult.Result)" |
| 84 | + $testResult.Result | should not be Failed |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + } finally { |
| 90 | + Pop-Location |
| 91 | + } |
| 92 | + |
9 | 93 | } |
0 commit comments