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