1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
11
jc "github.com/juju/testing/checkers"
12
gc "gopkg.in/check.v1"
14
"github.com/juju/utils/ssh"
17
type fakeClient struct {
21
optionsArg *ssh.Options
29
func (cl *fakeClient) checkCalls(c *gc.C, host string, command []string, options *ssh.Options, copyArgs []string, calls ...string) {
30
c.Check(cl.hostArg, gc.Equals, host)
31
c.Check(cl.commandArg, jc.DeepEquals, command)
32
c.Check(cl.optionsArg, gc.Equals, options)
33
c.Check(cl.copyArgs, jc.DeepEquals, copyArgs)
34
c.Check(cl.calls, jc.DeepEquals, calls)
37
func (cl *fakeClient) Command(host string, command []string, options *ssh.Options) *ssh.Cmd {
38
cl.calls = append(cl.calls, "Command")
40
cl.commandArg = command
41
cl.optionsArg = options
44
cmd = ssh.TestNewCmd(&cl.impl)
49
func (cl *fakeClient) Copy(args []string, options *ssh.Options) error {
50
cl.calls = append(cl.calls, "Copy")
52
cl.optionsArg = options
56
type bufferWriter struct {
60
func (*bufferWriter) Close() error {
64
type fakeCommandImpl struct {
69
stdinData bufferWriter
75
stdoutData bytes.Buffer
76
stderrData bytes.Buffer
79
func (ci *fakeCommandImpl) checkCalls(c *gc.C, stdin io.Reader, stdout, stderr io.Writer, calls ...string) {
80
c.Check(ci.stdinArg, gc.Equals, stdin)
81
c.Check(ci.stdoutArg, gc.Equals, stdout)
82
c.Check(ci.stderrArg, gc.Equals, stderr)
83
c.Check(ci.calls, jc.DeepEquals, calls)
86
func (ci *fakeCommandImpl) checkStdin(c *gc.C, data string) {
87
c.Check(ci.stdinData.String(), gc.Equals, data)
90
func (ci *fakeCommandImpl) Start() error {
91
ci.calls = append(ci.calls, "Start")
95
func (ci *fakeCommandImpl) Wait() error {
96
ci.calls = append(ci.calls, "Wait")
100
func (ci *fakeCommandImpl) Kill() error {
101
ci.calls = append(ci.calls, "Kill")
105
func (ci *fakeCommandImpl) SetStdio(stdin io.Reader, stdout, stderr io.Writer) {
106
ci.calls = append(ci.calls, "SetStdio")
108
ci.stdoutArg = stdout
109
ci.stderrArg = stderr
112
func (ci *fakeCommandImpl) StdinPipe() (io.WriteCloser, io.Reader, error) {
113
ci.calls = append(ci.calls, "StdinPipe")
114
return &ci.stdinData, ci.stdinRaw, ci.err
117
func (ci *fakeCommandImpl) StdoutPipe() (io.ReadCloser, io.Writer, error) {
118
ci.calls = append(ci.calls, "StdoutPipe")
119
return ioutil.NopCloser(&ci.stdoutData), ci.stdoutRaw, ci.err
122
func (ci *fakeCommandImpl) StderrPipe() (io.ReadCloser, io.Writer, error) {
123
ci.calls = append(ci.calls, "StderrPipe")
124
return ioutil.NopCloser(&ci.stderrData), ci.stderrRaw, ci.err