github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/worker/uniter/hook/hook_test.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package hook_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	gc "launchpad.net/gocheck"
    10  
    11  	"github.com/juju/juju/charm/hooks"
    12  	"github.com/juju/juju/worker/uniter/hook"
    13  )
    14  
    15  func Test(t *testing.T) {
    16  	gc.TestingT(t)
    17  }
    18  
    19  type InfoSuite struct{}
    20  
    21  var _ = gc.Suite(&InfoSuite{})
    22  
    23  var validateTests = []struct {
    24  	info hook.Info
    25  	err  string
    26  }{
    27  	{
    28  		hook.Info{Kind: hooks.RelationJoined},
    29  		`"relation-joined" hook requires a remote unit`,
    30  	}, {
    31  		hook.Info{Kind: hooks.RelationChanged},
    32  		`"relation-changed" hook requires a remote unit`,
    33  	}, {
    34  		hook.Info{Kind: hooks.RelationDeparted},
    35  		`"relation-departed" hook requires a remote unit`,
    36  	}, {
    37  		hook.Info{Kind: hooks.Kind("grok")},
    38  		`unknown hook kind "grok"`,
    39  	},
    40  	{hook.Info{Kind: hooks.Install}, ""},
    41  	{hook.Info{Kind: hooks.Start}, ""},
    42  	{hook.Info{Kind: hooks.ConfigChanged}, ""},
    43  	{hook.Info{Kind: hooks.UpgradeCharm}, ""},
    44  	{hook.Info{Kind: hooks.Stop}, ""},
    45  	{hook.Info{Kind: hooks.RelationJoined, RemoteUnit: "x"}, ""},
    46  	{hook.Info{Kind: hooks.RelationChanged, RemoteUnit: "x"}, ""},
    47  	{hook.Info{Kind: hooks.RelationDeparted, RemoteUnit: "x"}, ""},
    48  	{hook.Info{Kind: hooks.RelationBroken}, ""},
    49  }
    50  
    51  func (s *InfoSuite) TestValidate(c *gc.C) {
    52  	for i, t := range validateTests {
    53  		c.Logf("test %d", i)
    54  		err := t.info.Validate()
    55  		if t.err == "" {
    56  			c.Assert(err, gc.IsNil)
    57  		} else {
    58  			c.Assert(err, gc.ErrorMatches, t.err)
    59  		}
    60  	}
    61  }