github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/jujud/agent/model/agent_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package model_test
     5  
     6  import (
     7  	gc "gopkg.in/check.v1"
     8  
     9  	"github.com/juju/errors"
    10  	"github.com/juju/names"
    11  	"github.com/juju/testing"
    12  	jc "github.com/juju/testing/checkers"
    13  
    14  	"github.com/juju/juju/agent"
    15  	"github.com/juju/juju/api"
    16  	"github.com/juju/juju/cmd/jujud/agent/model"
    17  	coretesting "github.com/juju/juju/testing"
    18  )
    19  
    20  type WrapAgentSuite struct {
    21  	testing.IsolationSuite
    22  }
    23  
    24  var _ = gc.Suite(&WrapAgentSuite{})
    25  
    26  func (s *WrapAgentSuite) TestRequiresUUID(c *gc.C) {
    27  	agent, err := model.WrapAgent(&mockAgent{}, "lol-nope-no-hope")
    28  	c.Check(err, gc.ErrorMatches, `model uuid "lol-nope-no-hope" not valid`)
    29  	c.Check(err, jc.Satisfies, errors.IsNotValid)
    30  	c.Check(agent, gc.IsNil)
    31  }
    32  
    33  func (s *WrapAgentSuite) TestWraps(c *gc.C) {
    34  	agent, err := model.WrapAgent(&mockAgent{}, coretesting.ModelTag.Id())
    35  	c.Assert(err, jc.ErrorIsNil)
    36  	config := agent.CurrentConfig()
    37  
    38  	c.Check(config.Model(), gc.Equals, coretesting.ModelTag)
    39  	c.Check(config.OldPassword(), gc.Equals, "")
    40  
    41  	apiInfo, ok := config.APIInfo()
    42  	c.Assert(ok, jc.IsTrue)
    43  	c.Check(apiInfo, gc.DeepEquals, &api.Info{
    44  		Addrs:    []string{"here", "there"},
    45  		CACert:   "trust-me",
    46  		ModelTag: coretesting.ModelTag,
    47  		Tag:      names.NewMachineTag("123"),
    48  		Password: "12345",
    49  		Nonce:    "11111",
    50  	})
    51  }
    52  
    53  type mockAgent struct{ agent.Agent }
    54  
    55  func (mock *mockAgent) CurrentConfig() agent.Config {
    56  	return &mockConfig{}
    57  }
    58  
    59  type mockConfig struct{ agent.Config }
    60  
    61  func (mock *mockConfig) Model() names.ModelTag {
    62  	return names.NewModelTag("mock-model-uuid")
    63  }
    64  
    65  func (mock *mockConfig) APIInfo() (*api.Info, bool) {
    66  	return &api.Info{
    67  		Addrs:    []string{"here", "there"},
    68  		CACert:   "trust-me",
    69  		ModelTag: names.NewModelTag("mock-model-uuid"),
    70  		Tag:      names.NewMachineTag("123"),
    71  		Password: "12345",
    72  		Nonce:    "11111",
    73  	}, true
    74  }
    75  
    76  func (mock *mockConfig) OldPassword() string {
    77  	return "do-not-use"
    78  }