github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/storage/provider/package_test.go (about)

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