github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/worker/apicaller/util_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package apicaller_test 5 6 import ( 7 "github.com/juju/names" 8 "github.com/juju/testing" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 12 "github.com/juju/juju/agent" 13 "github.com/juju/juju/api" 14 coretesting "github.com/juju/juju/testing" 15 "github.com/juju/juju/worker" 16 ) 17 18 type mockAgent struct { 19 agent.Agent 20 stub *testing.Stub 21 env names.EnvironTag 22 } 23 24 func (mock *mockAgent) CurrentConfig() agent.Config { 25 return dummyConfig{env: mock.env} 26 } 27 28 func (mock *mockAgent) ChangeConfig(mutator agent.ConfigMutator) error { 29 mock.stub.AddCall("ChangeConfig", mutator) 30 return mock.stub.NextErr() 31 } 32 33 type dummyConfig struct { 34 agent.Config 35 env names.EnvironTag 36 } 37 38 func (dummy dummyConfig) Environment() names.EnvironTag { 39 return dummy.env 40 } 41 42 type mockSetter struct { 43 stub *testing.Stub 44 agent.ConfigSetter 45 } 46 47 func (mock *mockSetter) Migrate(params agent.MigrateParams) error { 48 mock.stub.AddCall("Migrate", params) 49 return mock.stub.NextErr() 50 } 51 52 type mockConn struct { 53 stub *testing.Stub 54 api.Connection 55 broken chan struct{} 56 } 57 58 func (mock *mockConn) EnvironTag() (names.EnvironTag, error) { 59 mock.stub.AddCall("EnvironTag") 60 if err := mock.stub.NextErr(); err != nil { 61 return names.EnvironTag{}, err 62 } 63 return coretesting.EnvironmentTag, nil 64 } 65 66 func (mock *mockConn) Broken() <-chan struct{} { 67 return mock.broken 68 } 69 70 func (mock *mockConn) Close() error { 71 mock.stub.AddCall("Close") 72 return mock.stub.NextErr() 73 } 74 75 type mockGate struct { 76 stub *testing.Stub 77 } 78 79 func (mock *mockGate) Unlock() { 80 mock.stub.AddCall("Unlock") 81 } 82 83 type dummyWorker struct { 84 worker.Worker 85 } 86 87 func assertStop(c *gc.C, w worker.Worker) { 88 c.Assert(worker.Stop(w), jc.ErrorIsNil) 89 } 90 91 func assertStopError(c *gc.C, w worker.Worker, match string) { 92 c.Assert(worker.Stop(w), gc.ErrorMatches, match) 93 }