Skip to content

Commit

Permalink
(maint) Update pester tests for new linux escaping
Browse files Browse the repository at this point in the history
This commit updates the pester tests for the pwsh module to correctly test for
the new format of params parsing on unix based platforms
  • Loading branch information
mcdonaldseanp committed Feb 19, 2021
1 parent c2c466c commit 10675b4
Show file tree
Hide file tree
Showing 2 changed files with 2,194 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pwsh_module/command.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@ Describe "test all bolt command examples" {
It "bolt plan run canary --targets target1,target2 command=hostname" {
Write-Warning 'requires params to not be positionl...is that a problem'
$result = Invoke-BoltPlan -name 'canary' -targets 'target1,target2' -params @{ 'command' = 'hostname' }
$result | Should -Be "bolt plan run canary --targets target1,target2 --params '{`"command`":`"hostname`"}'"
# Linux platforms and windows platforms will format the param strings differently:
# on windows the format is wrapped in single qoutes with no backslash, while linux
# variants require backslash escaped quotes and no single quote wrapping
if ($IsWindows) {
$result | Should -Be "bolt plan run canary --targets target1,target2 --params '{`"command`":`"hostname`"}'"
} else {
$result | Should -Be "bolt plan run canary --targets target1,target2 --params {\`"command\`":\`"hostname\`"}"
}
}
It "bolt plan new myproject::myplan" {
$result = New-BoltPlan -name 'myproject::myplan'
Expand Down Expand Up @@ -274,11 +281,20 @@ Describe "test all bolt command examples" {
$results | Should -Be "bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'"

$results = Invoke-BoltTask -name 'package' -targets 'target1,target2' -params @{ 'name' = 'bash'; 'action' = 'status' }
# We don't care about the order of JSON keys, and they might become out
# of order due to ConvertToJson
$results | Should -BeIn @("bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'",
"bolt task run package --targets target1,target2 --params '{`"action`":`"status`",`"name`":`"bash`"}'")

# Linux platforms and windows platforms will format the param strings differently:
# on windows the format is wrapped in single qoutes with no backslash, while linux
# variants require backslash escaped quotes and no single quote wrapping
if ($IsWindows) {
# We don't care about the order of JSON keys, and they might become out
# of order due to ConvertToJson
$results | Should -BeIn @("bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'",
"bolt task run package --targets target1,target2 --params '{`"action`":`"status`",`"name`":`"bash`"}'")
} else {
# We don't care about the order of JSON keys, and they might become out
# of order due to ConvertToJson
$results | Should -BeIn @("bolt task run package --targets target1,target2 --params {\`"name\`":\`"bash\`",\`"action\`":\`"status\`"}",
"bolt task run package --targets target1,target2 --params {\`"action\`":\`"status\`",\`"name\`":\`"bash\`"}")
}
}
It "bolt task show" {
$results = Get-BoltTask
Expand Down
Loading

0 comments on commit 10675b4

Please sign in to comment.