github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/juju/charm.v6-unstable/hooks" 10 11 "github.com/juju/juju/testing" 12 "github.com/juju/juju/worker/uniter/hook" 13 ) 14 15 type InfoSuite struct { 16 testing.BaseSuite 17 } 18 19 var _ = gc.Suite(&InfoSuite{}) 20 21 var validateTests = []struct { 22 info hook.Info 23 err string 24 }{ 25 { 26 hook.Info{Kind: hooks.RelationJoined}, 27 `"relation-joined" hook requires a remote unit`, 28 }, { 29 hook.Info{Kind: hooks.RelationChanged}, 30 `"relation-changed" hook requires a remote unit`, 31 }, { 32 hook.Info{Kind: hooks.RelationDeparted}, 33 `"relation-departed" hook requires a remote unit`, 34 }, { 35 hook.Info{Kind: hooks.Kind("grok")}, 36 `unknown hook kind "grok"`, 37 }, 38 {hook.Info{Kind: hooks.Install}, ""}, 39 {hook.Info{Kind: hooks.Start}, ""}, 40 {hook.Info{Kind: hooks.ConfigChanged}, ""}, 41 {hook.Info{Kind: hooks.CollectMetrics}, ""}, 42 {hook.Info{Kind: hooks.MeterStatusChanged}, ""}, 43 {hook.Info{Kind: hooks.Action}, "hooks.Kind Action is deprecated"}, 44 {hook.Info{Kind: hooks.UpgradeCharm}, ""}, 45 {hook.Info{Kind: hooks.Stop}, ""}, 46 {hook.Info{Kind: hooks.RelationJoined, RemoteUnit: "x"}, ""}, 47 {hook.Info{Kind: hooks.RelationChanged, RemoteUnit: "x"}, ""}, 48 {hook.Info{Kind: hooks.RelationDeparted, RemoteUnit: "x"}, ""}, 49 {hook.Info{Kind: hooks.RelationBroken}, ""}, 50 {hook.Info{Kind: hooks.StorageAttached}, `invalid storage ID ""`}, 51 {hook.Info{Kind: hooks.StorageAttached, StorageId: "data/0"}, ""}, 52 {hook.Info{Kind: hooks.StorageDetaching, StorageId: "data/0"}, ""}, 53 } 54 55 func (s *InfoSuite) TestValidate(c *gc.C) { 56 for i, t := range validateTests { 57 c.Logf("test %d", i) 58 err := t.info.Validate() 59 if t.err == "" { 60 c.Assert(err, jc.ErrorIsNil) 61 } else { 62 c.Assert(err, gc.ErrorMatches, t.err) 63 } 64 } 65 }