Skip to content

Instantly share code, notes, and snippets.

@bateskevin
Created February 14, 2020 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bateskevin/49e3ad5d3af6ab9ddd4caae0be4332ea to your computer and use it in GitHub Desktop.
Save bateskevin/49e3ad5d3af6ab9ddd4caae0be4332ea to your computer and use it in GitHub Desktop.
Running Pester Tests from Module in Linux Containers with Powershell
Function Invoke-DockerPester {
param(
$ContainerName = "DockerPester",
$Image,
$InputFolder,
$PathOnContainer = "/var",
$PathToTests
)
if(!($PathToTests)){
$PathToTests = "$(Join-Path $(join-path $PathOnContainer (split-path $InputFolder -Leaf)) "Tests")"
}
docker run -it -d -t --name $ContainerName $Image
$CPString = "$($ContainerName):$($PathOnContainer)"
docker cp $InputFolder $CPString
docker exec $ContainerName pwsh -command "Install-Module Pester -Force"
docker exec $ContainerName pwsh -command "ipmo pester"
docker exec $ContainerName pwsh -command "cd $PathToTests"
docker exec -it $ContainerName pwsh -command "Invoke-Pester $PathToTests"
#docker exec -it $ContainerName pwsh -command "$res | convertto-json"
docker rm --force $ContainerName
}
Invoke-DockerPester -Image "mcr.microsoft.com/powershell:7.0.0-rc.2-alpine-3.10" -InputFolder "/Users/kevin/code/PSHarmonize"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment