~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/testing/fakenotifywatcher.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package testing
 
5
 
 
6
import (
 
7
        "launchpad.net/tomb"
 
8
 
 
9
        "github.com/juju/juju/state"
 
10
)
 
11
 
 
12
// FakeNotifyWatcher is an implementation of state.NotifyWatcher which
 
13
// is useful in tests.
 
14
type FakeNotifyWatcher struct {
 
15
        tomb tomb.Tomb
 
16
        C    chan struct{}
 
17
}
 
18
 
 
19
var _ state.NotifyWatcher = (*FakeNotifyWatcher)(nil)
 
20
 
 
21
func NewFakeNotifyWatcher() *FakeNotifyWatcher {
 
22
        return &FakeNotifyWatcher{
 
23
                C: make(chan struct{}, 1),
 
24
        }
 
25
}
 
26
 
 
27
func (w *FakeNotifyWatcher) Stop() error {
 
28
        w.Kill()
 
29
        return w.Wait()
 
30
}
 
31
 
 
32
func (w *FakeNotifyWatcher) Kill() {
 
33
        w.tomb.Kill(nil)
 
34
        w.tomb.Done()
 
35
}
 
36
 
 
37
func (w *FakeNotifyWatcher) Wait() error {
 
38
        return w.tomb.Wait()
 
39
}
 
40
 
 
41
func (w *FakeNotifyWatcher) Err() error {
 
42
        return w.tomb.Err()
 
43
}
 
44
 
 
45
func (w *FakeNotifyWatcher) Changes() <-chan struct{} {
 
46
        return w.C
 
47
}