github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/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 coreagent "github.com/juju/juju/agent" 13 coretesting "github.com/juju/juju/testing" 14 "github.com/juju/juju/worker" 15 "github.com/juju/juju/worker/agent" 16 "github.com/juju/juju/worker/apicaller" 17 ) 18 19 type mockAgent struct { 20 agent.Agent 21 stub *testing.Stub 22 env names.EnvironTag 23 } 24 25 func (mock *mockAgent) CurrentConfig() coreagent.Config { 26 return dummyConfig{env: mock.env} 27 } 28 29 func (mock *mockAgent) ChangeConfig(mutator coreagent.ConfigMutator) error { 30 mock.stub.AddCall("ChangeConfig", mutator) 31 return mock.stub.NextErr() 32 } 33 34 type dummyConfig struct { 35 coreagent.Config 36 env names.EnvironTag 37 } 38 39 func (dummy dummyConfig) Environment() names.EnvironTag { 40 return dummy.env 41 } 42 43 type mockSetter struct { 44 stub *testing.Stub 45 coreagent.ConfigSetter 46 } 47 48 func (mock *mockSetter) Migrate(params coreagent.MigrateParams) error { 49 mock.stub.AddCall("Migrate", params) 50 return mock.stub.NextErr() 51 } 52 53 type mockConn struct { 54 stub *testing.Stub 55 apicaller.Connection 56 broken chan struct{} 57 } 58 59 func (mock *mockConn) EnvironTag() (names.EnvironTag, error) { 60 mock.stub.AddCall("EnvironTag") 61 if err := mock.stub.NextErr(); err != nil { 62 return names.EnvironTag{}, err 63 } 64 return coretesting.EnvironmentTag, nil 65 } 66 67 func (mock *mockConn) Broken() <-chan struct{} { 68 return mock.broken 69 } 70 71 func (mock *mockConn) Close() error { 72 mock.stub.AddCall("Close") 73 return mock.stub.NextErr() 74 } 75 76 type dummyWorker struct { 77 worker.Worker 78 } 79 80 func assertStop(c *gc.C, w worker.Worker) { 81 c.Assert(worker.Stop(w), jc.ErrorIsNil) 82 } 83 84 func assertStopError(c *gc.C, w worker.Worker, match string) { 85 c.Assert(worker.Stop(w), gc.ErrorMatches, match) 86 }