github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/provisioner/manifold_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package provisioner_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/agent"
    13  	"github.com/juju/juju/api/base"
    14  	"github.com/juju/juju/worker/dependency"
    15  	dt "github.com/juju/juju/worker/dependency/testing"
    16  	"github.com/juju/juju/worker/provisioner"
    17  )
    18  
    19  type ManifoldSuite struct {
    20  	testing.IsolationSuite
    21  }
    22  
    23  var _ = gc.Suite(&ManifoldSuite{})
    24  
    25  func (s *ManifoldSuite) TestManifold(c *gc.C) {
    26  	manifold := provisioner.Manifold(provisioner.ManifoldConfig{
    27  		AgentName:     "jeff",
    28  		APICallerName: "barry",
    29  	})
    30  
    31  	c.Check(manifold.Inputs, jc.DeepEquals, []string{"jeff", "barry"})
    32  	c.Check(manifold.Output, gc.IsNil)
    33  	c.Check(manifold.Start, gc.NotNil)
    34  	// manifold.Start is tested extensively via direct use in provisioner_test
    35  }
    36  
    37  func (s *ManifoldSuite) TestMissingAgent(c *gc.C) {
    38  	manifold := provisioner.Manifold(provisioner.ManifoldConfig{
    39  		AgentName:     "agent",
    40  		APICallerName: "api-caller",
    41  	})
    42  	w, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
    43  		"agent":      dependency.ErrMissing,
    44  		"api-caller": struct{ base.APICaller }{},
    45  	}))
    46  	c.Check(w, gc.IsNil)
    47  	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
    48  }
    49  
    50  func (s *ManifoldSuite) TestMissingAPICaller(c *gc.C) {
    51  	manifold := provisioner.Manifold(provisioner.ManifoldConfig{
    52  		AgentName:     "agent",
    53  		APICallerName: "api-caller",
    54  	})
    55  	w, err := manifold.Start(dt.StubContext(nil, map[string]interface{}{
    56  		"agent":      struct{ agent.Agent }{},
    57  		"api-caller": dependency.ErrMissing,
    58  	}))
    59  	c.Check(w, gc.IsNil)
    60  	c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
    61  }