github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/workertest/fake_watcher.go (about)

     1  package workertest
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/juju/juju/worker"
     7  )
     8  
     9  type NotAWatcher struct {
    10  	changes chan struct{}
    11  	worker.Worker
    12  }
    13  
    14  // NewFakeWatcher returns a fake watcher
    15  func NewFakeWatcher(len, preload int) NotAWatcher {
    16  	if len < preload {
    17  		panic("len must be larger than preload")
    18  	}
    19  	ch := make(chan struct{}, len)
    20  	for i := 0; i < preload; i++ {
    21  		ch <- struct{}{}
    22  	}
    23  	return NotAWatcher{
    24  		changes: ch,
    25  		Worker:  NewErrorWorker(nil),
    26  	}
    27  }
    28  
    29  func (w NotAWatcher) Changes() <-chan struct{} {
    30  	return w.changes
    31  }
    32  
    33  func (w NotAWatcher) Stop() error {
    34  	return nil
    35  }
    36  
    37  func (w NotAWatcher) Err() error {
    38  	return errors.New("An error")
    39  }
    40  
    41  func (w *NotAWatcher) Ping() {
    42  	w.changes <- struct{}{}
    43  }
    44  
    45  func (w *NotAWatcher) Close() {
    46  	close(w.changes)
    47  }