1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/testing"
8
"gopkg.in/juju/names.v2"
10
"github.com/juju/juju/core/life"
11
"github.com/juju/juju/watcher"
12
"github.com/juju/juju/worker"
13
"github.com/juju/juju/worker/workertest"
16
func newMockFacade(stub *testing.Stub, lifeResults ...life.Value) *mockFacade {
19
lifeResults: lifeResults,
23
type mockFacade struct {
25
lifeResults []life.Value
28
func (mock *mockFacade) Life(entity names.Tag) (life.Value, error) {
29
mock.stub.AddCall("Life", entity)
30
if err := mock.stub.NextErr(); err != nil {
33
return mock.nextLife(), nil
36
func (mock *mockFacade) nextLife() life.Value {
37
result := mock.lifeResults[0]
38
mock.lifeResults = mock.lifeResults[1:]
42
func (mock *mockFacade) Watch(entity names.Tag) (watcher.NotifyWatcher, error) {
43
mock.stub.AddCall("Watch", entity)
44
if err := mock.stub.NextErr(); err != nil {
48
changes := make(chan struct{}, count)
49
for i := 0; i < count; i++ {
52
return newMockWatcher(changes), nil
55
type mockWatcher struct {
60
func newMockWatcher(changes chan struct{}) *mockWatcher {
62
Worker: workertest.NewErrorWorker(nil),
67
func (mock *mockWatcher) Changes() watcher.NotifyChannel {