/
fakenotifywatcher.go
44 lines (36 loc) · 1.02 KB
/
fakenotifywatcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package testing
import (
"github.com/juju/juju/state"
"github.com/juju/juju/worker"
"github.com/juju/juju/worker/workertest"
)
// FakeNotifyWatcher is an implementation of state.NotifyWatcher which
// is useful in tests.
type FakeNotifyWatcher struct {
worker.Worker
C chan struct{}
}
var _ state.NotifyWatcher = (*FakeNotifyWatcher)(nil)
func NewFakeNotifyWatcher() *FakeNotifyWatcher {
ch := make(chan struct{}, 1)
ch <- struct{}{}
return &FakeNotifyWatcher{
Worker: workertest.NewErrorWorker(nil),
C: ch,
}
}
// Stop is part of the state.NotifyWatcher interface.
func (w *FakeNotifyWatcher) Stop() error {
return worker.Stop(w)
}
// Err is part of the state.NotifyWatcher interface.
func (w *FakeNotifyWatcher) Err() error {
// this is silly, but it's what it always returned anyway
return nil
}
// Changes is part of the state.NotifyWatcher interface.
func (w *FakeNotifyWatcher) Changes() <-chan struct{} {
return w.C
}