github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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 "github.com/juju/utils/featureflag" 9 gc "gopkg.in/check.v1" 10 "gopkg.in/juju/charm.v4/hooks" 11 12 "github.com/juju/juju/juju/osenv" 13 "github.com/juju/juju/testing" 14 "github.com/juju/juju/worker/uniter/hook" 15 ) 16 17 type InfoSuite struct { 18 testing.BaseSuite 19 } 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.CollectMetrics}, ""}, 44 {hook.Info{Kind: hooks.MeterStatusChanged}, ""}, 45 { 46 hook.Info{Kind: hooks.Action}, 47 `action id "" cannot be parsed as an action tag`, 48 }, 49 {hook.Info{Kind: hooks.Action, ActionId: "badadded-0123-4567-89ab-cdef01234567"}, ""}, 50 {hook.Info{Kind: hooks.UpgradeCharm}, ""}, 51 {hook.Info{Kind: hooks.Stop}, ""}, 52 {hook.Info{Kind: hooks.RelationJoined, RemoteUnit: "x"}, ""}, 53 {hook.Info{Kind: hooks.RelationChanged, RemoteUnit: "x"}, ""}, 54 {hook.Info{Kind: hooks.RelationDeparted, RemoteUnit: "x"}, ""}, 55 {hook.Info{Kind: hooks.RelationBroken}, ""}, 56 {hook.Info{Kind: hooks.StorageAttached}, ""}, 57 {hook.Info{Kind: hooks.StorageDetached}, ""}, 58 } 59 60 func (s *InfoSuite) TestValidate(c *gc.C) { 61 s.PatchEnvironment(osenv.JujuFeatureFlagEnvKey, "storage") 62 featureflag.SetFlagsFromEnvironment(osenv.JujuFeatureFlagEnvKey) 63 for i, t := range validateTests { 64 c.Logf("test %d", i) 65 err := t.info.Validate() 66 if t.err == "" { 67 c.Assert(err, jc.ErrorIsNil) 68 } else { 69 c.Assert(err, gc.ErrorMatches, t.err) 70 } 71 } 72 } 73 74 func (s *InfoSuite) TestStorageHooksRequireFeatureFlag(c *gc.C) { 75 err := hook.Info{Kind: hooks.StorageAttached}.Validate() 76 c.Assert(err, gc.ErrorMatches, `unknown hook kind "storage-attached"`) 77 err = hook.Info{Kind: hooks.StorageDetached}.Validate() 78 c.Assert(err, gc.ErrorMatches, `unknown hook kind "storage-detached"`) 79 }