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

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package testing
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  
    10  	"github.com/juju/juju/worker"
    11  )
    12  
    13  var _ worker.Worker = (*StubWorker)(nil)
    14  
    15  // StubWorker is a testing stub for worker.Worker.
    16  type StubWorker struct {
    17  	// Stub is the underlying testing stub.
    18  	Stub *testing.Stub
    19  }
    20  
    21  // NewStubWorker returns a new StubWorker.
    22  func NewStubWorker(stub *testing.Stub) *StubWorker {
    23  	return &StubWorker{
    24  		Stub: stub,
    25  	}
    26  }
    27  
    28  // Kill implements worker.Worker.
    29  func (w *StubWorker) Kill() {
    30  	w.Stub.AddCall("Kill")
    31  	w.Stub.NextErr()
    32  
    33  	// Do nothing.
    34  }
    35  
    36  // Wait implements worker.Worker.
    37  func (w *StubWorker) Wait() error {
    38  	w.Stub.AddCall("Wait")
    39  	if err := w.Stub.NextErr(); err != nil {
    40  		return errors.Trace(err)
    41  	}
    42  
    43  	// Do nothing.
    44  	return nil
    45  }