From 441b105fd82be6eef314907c952b6bf9fb5edf92 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 14:47:58 -0700 Subject: [PATCH] Made the test run in new powershell Ran the test with the same filter Imported the result cleaned up the test run --- test/powershell/SDK/CmdletExample.Tests.ps1 | 78 +++++++++++++++++++-- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/test/powershell/SDK/CmdletExample.Tests.ps1 b/test/powershell/SDK/CmdletExample.Tests.ps1 index 517d7a51a..25f64e715 100644 --- a/test/powershell/SDK/CmdletExample.Tests.ps1 +++ b/test/powershell/SDK/CmdletExample.Tests.ps1 @@ -1,9 +1,73 @@ -try { - $enlistmentRoot = git rev-parse --show-toplevel +# Looking at pester internal to get tag filter and ExcludeTagFilter +# This seems like the most stable way to do this +# other options like testing for tags seems more likely to break + +InModuleScope Pester { + Describe 'Getting Tag Filters' -Tag CI { + $global:__PesterTags = $pester.TagFilter + $global:__PesterExcludeTags = $pester.ExcludeTagFilter + } +} +Describe 'SDK Send Greeting Sample Tests' -Tag CI { + + try { + $enlistmentRoot = git rev-parse --show-toplevel + $docLocation = Join-Path -Path $enlistmentRoot -ChildPath '\docs\cmdlet-example' + $testResultPath = Join-Path $TestDrive 'sendgreetingresults.xml' + $sampleCopy = Join-Path $TestDrive 'sendgreeting' + $fullSampleCopyPath = Join-Path $sampleCopy 'cmdlet-example' + if(!(Test-Path $sampleCopy)) + { + New-Item -ItemType Directory -Path $sampleCopy + } + + Copy-Item -Recurse -Path $docLocation -Destination $sampleCopy -Force + dir -Recurse $sampleCopy | %{ Write-Verbose "sc: $($_.FullName)"} + +$pesterCommand = "Invoke-Pester $sampleCopy -PassThru" +if($global:__PesterTags) +{ + $pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')" +} + +if($global:__PesterExcludeTags) +{ + $pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')" +} + + $command = @" +Push-Location -Path $fullSampleCopyPath +Import-module $(Join-path $env:PSModulePath pester) +$pesterCommand | Export-Clixml -Path $testResultPath +"@ + + Write-Verbose -Message "command: '$command'" -Verbose + $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) + $encodedCommand = [Convert]::ToBase64String($bytes) + &"$PSHOME/Powershell.exe" -encodedCommand $encodedCommand + + it "Should have test results file" { + $testResultPath | should exist + $script:results = Import-Clixml $testResultPath + } + #$host.EnterNestedPrompt(); + it "Should have test results" { + $script:results | should not be BeNullOrEmpty + $script:results.TotalCount | should not BeNullOrEmpty + $script:results.TestResult.Count | should not BeNullOrEmpty + } + + foreach($testResult in $script:results.TestResult){ + it "Test $($testResult.Name) should not fail" { + $testResult.FailureMessage + $testResult.StackTrace | should BeNullOrEmpty + $testResult.ErrorRecord | should BeNullOrEmpty + Write-Verbose "Result: $($testResult.Result)" + $testResult.Result | should not be Failed + } + } + + } finally { + Pop-Location + } - $docLocation = [io.path]::Combine($enlistmentRoot, "docs","cmdlet-example") - Push-Location $docLocation - ./SendGreeting.Tests.ps1 -} finally { - Pop-Location }