-
Notifications
You must be signed in to change notification settings - Fork 129
/
response_test.go
86 lines (67 loc) · 2.16 KB
/
response_test.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package winrm
import (
"bytes"
"errors"
. "gopkg.in/check.v1"
)
func (s *WinRMSuite) TestOpenShellResponse(c *C) {
response := createShellResponse
shellID, err := ParseOpenShellResponse(response)
if err != nil {
c.Fatalf("response didn't parse: %s", err)
}
c.Assert("67A74734-DD32-4F10-89DE-49A060483810", Equals, shellID)
}
func (s *WinRMSuite) TestExecuteCommandResponse(c *C) {
response := executeCommandResponse
commandID, err := ParseExecuteCommandResponse(response)
if err != nil {
c.Fatalf("response didn't parse: %s", err)
}
c.Assert("1A6DEE6B-EC68-4DD6-87E9-030C0048ECC4", Equals, commandID)
}
func (s *WinRMSuite) TestExecuteCommandResponseError(c *C) {
response := executeCommandResponseWithError
commandID, err := ParseExecuteCommandResponse(response)
if err == nil {
c.Fatal("expected error")
}
c.Assert(commandID, Equals, "")
var execCmdRespErr *ExecuteCommandError
if !errors.As(err, &execCmdRespErr) {
c.Fatal("expected err to be of type ExecuteCommandError")
}
}
func (s *WinRMSuite) TestSlurpOutputResponse(c *C) {
response := outputResponse
var stdout, stderr bytes.Buffer
finished, _, err := ParseSlurpOutputErrResponse(response, &stdout, &stderr)
if err != nil {
c.Fatalf("response didn't parse: %s", err)
}
c.Assert(finished, Equals, false)
c.Assert("That's all folks!!!", Equals, stdout.String())
c.Assert("This is stderr, I'm pretty sure!", Equals, stderr.String())
}
func (s *WinRMSuite) TestSlurpOutputSingleResponse(c *C) {
response := singleOutputResponse
var stream bytes.Buffer
finished, _, err := ParseSlurpOutputResponse(response, &stream, "stdout")
if err != nil {
c.Fatalf("response didn't parse: %s", err)
}
c.Assert(finished, Equals, false)
c.Assert("That's all folks!!!", Equals, stream.String())
}
func (s *WinRMSuite) TestDoneSlurpOutputResponse(c *C) {
response := doneCommandResponse
var stdout, stderr bytes.Buffer
finished, code, err := ParseSlurpOutputErrResponse(response, &stdout, &stderr)
if err != nil {
c.Fatalf("response didn't parse: %s", err)
}
c.Assert(finished, Equals, true)
c.Assert(code, Equals, 123)
c.Assert("", Equals, stdout.String())
c.Assert("", Equals, stderr.String())
}