~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/storage/looputil/util_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package looputil_test
 
5
 
 
6
import gc "gopkg.in/check.v1"
 
7
 
 
8
type mockRunCommand struct {
 
9
        c        *gc.C
 
10
        commands []*mockCommand
 
11
}
 
12
 
 
13
type mockCommand struct {
 
14
        cmd    string
 
15
        args   []string
 
16
        result string
 
17
        err    error
 
18
}
 
19
 
 
20
func (m *mockCommand) respond(result string, err error) {
 
21
        m.result = result
 
22
        m.err = err
 
23
}
 
24
 
 
25
func (m *mockRunCommand) expect(cmd string, args ...string) *mockCommand {
 
26
        command := &mockCommand{cmd: cmd, args: args}
 
27
        m.commands = append(m.commands, command)
 
28
        return command
 
29
}
 
30
 
 
31
func (m *mockRunCommand) assertDrained() {
 
32
        m.c.Assert(m.commands, gc.HasLen, 0)
 
33
}
 
34
 
 
35
func (m *mockRunCommand) run(cmd string, args ...string) (stdout string, err error) {
 
36
        m.c.Assert(m.commands, gc.Not(gc.HasLen), 0)
 
37
        expect := m.commands[0]
 
38
        m.commands = m.commands[1:]
 
39
        m.c.Assert(cmd, gc.Equals, expect.cmd)
 
40
        m.c.Assert(args, gc.DeepEquals, expect.args)
 
41
        return expect.result, expect.err
 
42
}