forked from hnakamur/go-powershell
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshell_test.go
More file actions
42 lines (37 loc) · 888 Bytes
/
shell_test.go
File metadata and controls
42 lines (37 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package powershell_test
import (
"strings"
"testing"
"github.com/ycyun/go-powershell"
)
func TestShell_Exec(t *testing.T) {
shell, err := powershell.New()
if err != nil {
t.Fatal(err)
}
defer shell.Exit()
cases := []struct {
command string
want string
}{
{"echo こんにちは", "こんにちは"},
{"Get-TimeZone | Select-Object StandardName",
func() string {
if shell.CodePage() == 65001 {
return "StandardName \r\n------------ \r\nTokyo Standard Time"
}
return "StandardName \r\n------------ \r\n東京 (標準時)"
}(),
},
}
for i, c := range cases {
stdout, err := shell.Exec(c.command)
if err != nil {
t.Errorf("error from exec, caseID=%d, commnad=%s: %s", i, c.command, err)
}
got := strings.TrimSpace(stdout)
if got != c.want {
t.Errorf("unexpected output: got=%q, want=%q", got, c.want)
}
}
}