github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/applicationscaler/worker_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package applicationscaler_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/worker"
    13  	"github.com/juju/juju/worker/applicationscaler"
    14  )
    15  
    16  type WorkerSuite struct {
    17  	testing.IsolationSuite
    18  }
    19  
    20  var _ = gc.Suite(&WorkerSuite{})
    21  
    22  func (s *WorkerSuite) TestValidate(c *gc.C) {
    23  	config := applicationscaler.Config{}
    24  	check := func(err error) {
    25  		c.Check(err, gc.ErrorMatches, "nil Facade not valid")
    26  		c.Check(err, jc.Satisfies, errors.IsNotValid)
    27  	}
    28  
    29  	err := config.Validate()
    30  	check(err)
    31  
    32  	worker, err := applicationscaler.New(config)
    33  	check(err)
    34  	c.Check(worker, gc.IsNil)
    35  }
    36  
    37  func (s *WorkerSuite) TestWatchError(c *gc.C) {
    38  	fix := newFixture(c, errors.New("zap ouch"))
    39  	fix.Run(c, func(worker worker.Worker) {
    40  		err := worker.Wait()
    41  		c.Check(err, gc.ErrorMatches, "zap ouch")
    42  	})
    43  	fix.CheckCallNames(c, "Watch")
    44  }
    45  
    46  func (s *WorkerSuite) TestRescaleThenError(c *gc.C) {
    47  	fix := newFixture(c, nil, nil, errors.New("pew squish"))
    48  	fix.Run(c, func(worker worker.Worker) {
    49  		err := worker.Wait()
    50  		c.Check(err, gc.ErrorMatches, "pew squish")
    51  	})
    52  	fix.CheckCalls(c, []testing.StubCall{{
    53  		FuncName: "Watch",
    54  	}, {
    55  		FuncName: "Rescale",
    56  		Args:     []interface{}{[]string{"expected", "first"}},
    57  	}, {
    58  		FuncName: "Rescale",
    59  		Args:     []interface{}{[]string{"expected", "second"}},
    60  	}})
    61  }