github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/worker/uniter/relation/listsource_test.go (about)

     1  // Copyright 2012-2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package relation_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/juju/charm.v4/hooks"
    10  
    11  	"github.com/juju/juju/state/multiwatcher"
    12  	"github.com/juju/juju/worker/uniter/hook"
    13  	"github.com/juju/juju/worker/uniter/relation"
    14  )
    15  
    16  type ListSourceSuite struct{}
    17  
    18  var _ = gc.Suite(&ListSourceSuite{})
    19  
    20  func (s *ListSourceSuite) TestNoUpdates(c *gc.C) {
    21  	source := relation.NewListSource(hookList(hooks.Start, hooks.Stop))
    22  	c.Check(source.Changes(), gc.IsNil)
    23  
    24  	err := source.Update(multiwatcher.RelationUnitsChange{})
    25  	c.Check(err, gc.ErrorMatches, "HookSource does not accept updates")
    26  
    27  	err = source.Stop()
    28  	c.Check(err, jc.ErrorIsNil)
    29  }
    30  
    31  func (s *ListSourceSuite) TestQueue(c *gc.C) {
    32  	for i, test := range [][]hook.Info{
    33  		hookList(),
    34  		hookList(hooks.Install, hooks.Install),
    35  		hookList(hooks.Stop, hooks.Start, hooks.Stop),
    36  	} {
    37  		c.Logf("test %d: %v", i, test)
    38  		source := relation.NewListSource(test)
    39  		for _, expect := range test {
    40  			c.Check(source.Empty(), jc.IsFalse)
    41  			c.Check(source.Next(), gc.DeepEquals, expect)
    42  			source.Pop()
    43  		}
    44  		c.Check(source.Empty(), jc.IsTrue)
    45  		c.Check(source.Next, gc.PanicMatches, "HookSource is empty")
    46  		c.Check(source.Pop, gc.PanicMatches, "HookSource is empty")
    47  	}
    48  }