2015-06-21 07:36:07 -04:00
|
|
|
package powershell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
func TestOutput(t *testing.T) {
|
2016-06-30 15:21:57 -04:00
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
var ps PowerShellCmd
|
2016-06-30 02:14:42 -04:00
|
|
|
|
2016-06-30 15:21:57 -04:00
|
|
|
powershellAvailable, _, _ := IsPowershellAvailable()
|
|
|
|
|
|
|
|
if !powershellAvailable {
|
|
|
|
t.Skipf("powershell not installed")
|
2016-06-30 02:14:42 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
cmdOut, err := ps.Output("")
|
2015-06-21 07:36:07 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
if cmdOut != "" {
|
|
|
|
t.Fatalf("output '%v' is not ''", cmdOut)
|
|
|
|
}
|
|
|
|
|
|
|
|
trueOutput, err := ps.Output("$True")
|
2015-06-21 07:36:07 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if trueOutput != "True" {
|
|
|
|
t.Fatalf("output '%v' is not 'True'", trueOutput)
|
|
|
|
}
|
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
falseOutput, err := ps.Output("$False")
|
2015-06-21 07:36:07 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if falseOutput != "False" {
|
|
|
|
t.Fatalf("output '%v' is not 'False'", falseOutput)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunFile(t *testing.T) {
|
2015-06-21 09:59:37 -04:00
|
|
|
var ps PowerShellCmd
|
2016-06-30 15:21:57 -04:00
|
|
|
|
|
|
|
powershellAvailable, _, _ := IsPowershellAvailable()
|
|
|
|
|
|
|
|
if !powershellAvailable {
|
|
|
|
t.Skipf("powershell not installed")
|
2016-06-30 02:14:42 -04:00
|
|
|
return
|
|
|
|
}
|
2016-06-30 15:21:57 -04:00
|
|
|
|
|
|
|
var blockBuffer bytes.Buffer
|
|
|
|
blockBuffer.WriteString(`param([string]$a, [string]$b, [int]$x, [int]$y) if (Test-Path variable:global:ProgressPreference){$ProgressPreference="SilentlyContinue"}; $n = $x + $y; Write-Output "$a $b $n";`)
|
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
cmdOut, err := ps.Output(blockBuffer.String(), "a", "b", "5", "10")
|
2015-06-21 07:36:07 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-06-21 09:59:37 -04:00
|
|
|
if cmdOut != "a b 15" {
|
|
|
|
t.Fatalf("output '%v' is not 'a b 15'", cmdOut)
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|