github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/raft/rafttransport/mock_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package rafttransport_test 5 6 import ( 7 "context" 8 "net" 9 10 "github.com/hashicorp/raft" 11 "gopkg.in/juju/names.v2" 12 "gopkg.in/juju/worker.v1" 13 14 "github.com/juju/juju/agent" 15 "github.com/juju/juju/api" 16 "github.com/juju/testing" 17 ) 18 19 type mockAgent struct { 20 agent.Agent 21 conf mockAgentConfig 22 } 23 24 func (ma *mockAgent) CurrentConfig() agent.Config { 25 return &ma.conf 26 } 27 28 type mockAgentConfig struct { 29 agent.Config 30 tag names.Tag 31 apiInfo *api.Info 32 } 33 34 func (c *mockAgentConfig) Tag() names.Tag { 35 return c.tag 36 } 37 38 func (c *mockAgentConfig) APIInfo() (*api.Info, bool) { 39 return c.apiInfo, c.apiInfo != nil 40 } 41 42 type mockTransportWorker struct { 43 worker.Worker 44 raft.Transport 45 } 46 47 type mockAPIConnection struct { 48 api.Connection 49 testing.Stub 50 dialContext func(context.Context) (net.Conn, error) 51 } 52 53 func (c *mockAPIConnection) Close() error { 54 c.MethodCall(c, "Close") 55 return c.NextErr() 56 } 57 58 func (c *mockAPIConnection) DialConn(ctx context.Context) (net.Conn, error) { 59 c.MethodCall(c, "DialConn", ctx) 60 if err := c.NextErr(); err != nil { 61 return nil, err 62 } 63 return c.dialContext(ctx) 64 }