github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/resolver/locker_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package resolver_test 5 6 import ( 7 "github.com/juju/testing" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 "gopkg.in/juju/charm.v6-unstable/hooks" 11 12 "github.com/juju/juju/worker/fortress" 13 "github.com/juju/juju/worker/uniter/hook" 14 "github.com/juju/juju/worker/uniter/operation" 15 "github.com/juju/juju/worker/uniter/resolver" 16 ) 17 18 type GuardSuite struct { 19 guard *mockCharmDirGuard 20 } 21 22 var _ = gc.Suite(&GuardSuite{}) 23 24 func (s *GuardSuite) SetUpTest(c *gc.C) { 25 s.guard = &mockCharmDirGuard{} 26 } 27 28 func (s *GuardSuite) checkCall(c *gc.C, state operation.State, call string) { 29 err := resolver.UpdateCharmDir(state, s.guard, nil) 30 c.Assert(err, jc.ErrorIsNil) 31 s.guard.CheckCallNames(c, call) 32 } 33 34 func (s *GuardSuite) TestLockdownEmptyState(c *gc.C) { 35 s.checkCall(c, operation.State{}, "Lockdown") 36 } 37 38 func (s *GuardSuite) TestLockdownNotStarted(c *gc.C) { 39 s.checkCall(c, operation.State{Started: false}, "Lockdown") 40 } 41 42 func (s *GuardSuite) TestLockdownStartStopInvalid(c *gc.C) { 43 s.checkCall(c, operation.State{Started: true, Stopped: true}, "Lockdown") 44 } 45 46 func (s *GuardSuite) TestLockdownInstall(c *gc.C) { 47 s.checkCall(c, operation.State{Started: true, Stopped: false, Kind: operation.Install}, "Lockdown") 48 } 49 50 func (s *GuardSuite) TestLockdownUpgrade(c *gc.C) { 51 s.checkCall(c, operation.State{Started: true, Stopped: false, Kind: operation.Upgrade}, "Lockdown") 52 } 53 54 func (s *GuardSuite) TestLockdownRunHookUpgradeCharm(c *gc.C) { 55 s.checkCall(c, operation.State{ 56 Started: true, 57 Stopped: false, 58 Kind: operation.RunHook, 59 Hook: &hook.Info{ 60 Kind: hooks.UpgradeCharm, 61 }, 62 }, "Lockdown") 63 } 64 65 func (s *GuardSuite) TestUnlockStarted(c *gc.C) { 66 s.checkCall(c, operation.State{Started: true, Stopped: false}, "Unlock") 67 } 68 69 func (s *GuardSuite) TestUnlockStartedContinue(c *gc.C) { 70 s.checkCall(c, operation.State{Started: true, Stopped: false, Kind: operation.Continue}, "Unlock") 71 } 72 73 func (s *GuardSuite) TestUnlockStartedRunAction(c *gc.C) { 74 s.checkCall(c, operation.State{Started: true, Stopped: false, Kind: operation.RunAction}, "Unlock") 75 } 76 77 func (s *GuardSuite) TestUnlockConfigChanged(c *gc.C) { 78 s.checkCall(c, operation.State{ 79 Started: true, 80 Stopped: false, 81 Kind: operation.RunHook, 82 Hook: &hook.Info{ 83 Kind: hooks.ConfigChanged, 84 }, 85 }, "Unlock") 86 } 87 88 func (s *GuardSuite) TestLockdownAbortArg(c *gc.C) { 89 abort := make(fortress.Abort) 90 err := resolver.UpdateCharmDir(operation.State{}, s.guard, abort) 91 c.Assert(err, jc.ErrorIsNil) 92 s.guard.CheckCalls(c, []testing.StubCall{{FuncName: "Lockdown", Args: []interface{}{abort}}}) 93 }