launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/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 gc "launchpad.net/gocheck" 8 "testing" 9 10 "launchpad.net/juju-core/charm/hooks" 11 "launchpad.net/juju-core/worker/uniter/hook" 12 ) 13 14 func Test(t *testing.T) { 15 gc.TestingT(t) 16 } 17 18 type InfoSuite struct{} 19 20 var _ = gc.Suite(&InfoSuite{}) 21 22 var validateTests = []struct { 23 info hook.Info 24 err string 25 }{ 26 { 27 hook.Info{Kind: hooks.RelationJoined}, 28 `"relation-joined" hook requires a remote unit`, 29 }, { 30 hook.Info{Kind: hooks.RelationChanged}, 31 `"relation-changed" hook requires a remote unit`, 32 }, { 33 hook.Info{Kind: hooks.RelationDeparted}, 34 `"relation-departed" hook requires a remote unit`, 35 }, { 36 hook.Info{Kind: hooks.Kind("grok")}, 37 `unknown hook kind "grok"`, 38 }, 39 {hook.Info{Kind: hooks.Install}, ""}, 40 {hook.Info{Kind: hooks.Start}, ""}, 41 {hook.Info{Kind: hooks.ConfigChanged}, ""}, 42 {hook.Info{Kind: hooks.UpgradeCharm}, ""}, 43 {hook.Info{Kind: hooks.Stop}, ""}, 44 {hook.Info{Kind: hooks.RelationJoined, RemoteUnit: "x"}, ""}, 45 {hook.Info{Kind: hooks.RelationChanged, RemoteUnit: "x"}, ""}, 46 {hook.Info{Kind: hooks.RelationDeparted, RemoteUnit: "x"}, ""}, 47 {hook.Info{Kind: hooks.RelationBroken}, ""}, 48 } 49 50 func (s *InfoSuite) TestValidate(c *gc.C) { 51 for i, t := range validateTests { 52 c.Logf("test %d", i) 53 err := t.info.Validate() 54 if t.err == "" { 55 c.Assert(err, gc.IsNil) 56 } else { 57 c.Assert(err, gc.ErrorMatches, t.err) 58 } 59 } 60 }