github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/testing/agentapi.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "github.com/juju/juju/agent" 8 "github.com/juju/juju/api/base" 9 basetesting "github.com/juju/juju/api/base/testing" 10 "github.com/juju/juju/cmd/jujud/agent/util" 11 "github.com/juju/juju/worker" 12 "github.com/juju/juju/worker/dependency" 13 dt "github.com/juju/juju/worker/dependency/testing" 14 ) 15 16 // AgentApiManifoldTestConfig returns a AgentApiManifoldConfig 17 // suitable for use with RunAgentApiManifold. 18 func AgentApiManifoldTestConfig() util.AgentApiManifoldConfig { 19 return util.AgentApiManifoldConfig{ 20 AgentName: "agent-name", 21 APICallerName: "api-caller-name", 22 } 23 } 24 25 // RunAgentApiManifold is useful for testing manifolds based on 26 // AgentApiManifold. It takes the manifold, sets up the resources 27 // required to successfully pass AgentApiManifold's checks and then 28 // runs the manifold start func. 29 // 30 // An agent and apiCaller may be optionally provided. If they are nil, 31 // dummy barely-good-enough defaults will be used (these dummies are 32 // fine not actually used for much). 33 func RunAgentApiManifold( 34 manifold dependency.Manifold, agent agent.Agent, apiCaller base.APICaller, 35 ) (worker.Worker, error) { 36 if agent == nil { 37 agent = new(dummyAgent) 38 } 39 if apiCaller == nil { 40 apiCaller = basetesting.APICallerFunc( 41 func(string, int, string, string, interface{}, interface{}) error { 42 return nil 43 }) 44 } 45 context := dt.StubContext(nil, map[string]interface{}{ 46 "agent-name": agent, 47 "api-caller-name": apiCaller, 48 }) 49 return manifold.Start(context) 50 } 51 52 type dummyAgent struct { 53 agent.Agent 54 }