github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/apiserver/testing/fakenotifywatcher.go (about)

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