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

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package worker
     5  
     6  import (
     7  	"errors"
     8  
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/testing"
    12  )
    13  
    14  type simpleWorkerSuite struct {
    15  	testing.BaseSuite
    16  }
    17  
    18  var _ = gc.Suite(&simpleWorkerSuite{})
    19  
    20  var testError = errors.New("test error")
    21  
    22  func (s *simpleWorkerSuite) TestWait(c *gc.C) {
    23  	doWork := func(_ <-chan struct{}) error {
    24  		return testError
    25  	}
    26  
    27  	w := NewSimpleWorker(doWork)
    28  	c.Assert(w.Wait(), gc.Equals, testError)
    29  }
    30  
    31  func (s *simpleWorkerSuite) TestWaitNil(c *gc.C) {
    32  	doWork := func(_ <-chan struct{}) error {
    33  		return nil
    34  	}
    35  
    36  	w := NewSimpleWorker(doWork)
    37  	c.Assert(w.Wait(), gc.Equals, nil)
    38  }
    39  
    40  func (s *simpleWorkerSuite) TestKill(c *gc.C) {
    41  	doWork := func(stopCh <-chan struct{}) error {
    42  		<-stopCh
    43  		return testError
    44  	}
    45  
    46  	w := NewSimpleWorker(doWork)
    47  	w.Kill()
    48  	c.Assert(w.Wait(), gc.Equals, testError)
    49  
    50  	// test we can kill again without a panic
    51  	w.Kill()
    52  }