github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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  	"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/engine"
    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() engine.AgentAPIManifoldConfig {
    19  	return engine.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  }