File: response_test.go

package info (click to toggle)
golang-github-masterzen-winrm 0.0~git20200615.c42b513-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 288 kB
  • sloc: makefile: 28; sh: 14
file content (71 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download
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
package winrm

import (
	"bytes"

	. "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) 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())
}