github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/apiserver/agent/agent_v1_test.go (about)

     1  package agent_test
     2  
     3  import (
     4  	jc "github.com/juju/testing/checkers"
     5  	gc "gopkg.in/check.v1"
     6  
     7  	"github.com/juju/juju/apiserver/agent"
     8  	"github.com/juju/juju/apiserver/common"
     9  	"github.com/juju/juju/apiserver/params"
    10  	apiservertesting "github.com/juju/juju/apiserver/testing"
    11  	"github.com/juju/juju/state"
    12  )
    13  
    14  // V1 test suite, no additional or changed tests.
    15  
    16  func factoryWrapperV1(st *state.State, resources *common.Resources, auth common.Authorizer) (interface{}, error) {
    17  	return agent.NewAgentAPIV1(st, resources, auth)
    18  }
    19  
    20  type agentSuiteV1 struct {
    21  	baseSuite
    22  }
    23  
    24  var _ = gc.Suite(&agentSuiteV1{})
    25  
    26  func (s *agentSuiteV1) TestClearReboot(c *gc.C) {
    27  	api, err := agent.NewAgentAPIV1(s.State, s.resources, s.authorizer)
    28  	c.Assert(err, jc.ErrorIsNil)
    29  
    30  	err = s.machine1.SetRebootFlag(true)
    31  	c.Assert(err, jc.ErrorIsNil)
    32  
    33  	args := params.Entities{Entities: []params.Entity{
    34  		{Tag: s.machine0.Tag().String()},
    35  		{Tag: s.machine1.Tag().String()},
    36  	}}
    37  
    38  	rFlag, err := s.machine1.GetRebootFlag()
    39  	c.Assert(err, jc.ErrorIsNil)
    40  	c.Assert(rFlag, jc.IsTrue)
    41  
    42  	result, err := api.ClearReboot(args)
    43  	c.Assert(err, jc.ErrorIsNil)
    44  	c.Assert(result, gc.DeepEquals, params.ErrorResults{
    45  		Results: []params.ErrorResult{
    46  			{apiservertesting.ErrUnauthorized},
    47  			{nil},
    48  		},
    49  	})
    50  
    51  	rFlag, err = s.machine1.GetRebootFlag()
    52  	c.Assert(err, jc.ErrorIsNil)
    53  	c.Assert(rFlag, jc.IsFalse)
    54  }
    55  
    56  func (s *agentSuiteV1) TestAgentFailsWithNonAgent(c *gc.C) {
    57  	s.testAgentFailsWithNonAgentV0(c, factoryWrapperV1)
    58  }
    59  
    60  func (s *agentSuiteV1) TestAgentSucceedsWithUnitAgent(c *gc.C) {
    61  	s.testAgentSucceedsWithUnitAgentV0(c, factoryWrapperV1)
    62  }
    63  
    64  func (s *agentSuiteV1) TestGetEntities(c *gc.C) {
    65  	s.testGetEntitiesV0(c, s.newAPI(c))
    66  }
    67  
    68  func (s *agentSuiteV1) TestGetEntitiesContainer(c *gc.C) {
    69  	auth := s.authorizer
    70  	auth.Tag = s.container.Tag()
    71  	api, err := agent.NewAgentAPIV1(s.State, s.resources, auth)
    72  	c.Assert(err, jc.ErrorIsNil)
    73  	s.testGetEntitiesContainerV0(c, api)
    74  }
    75  
    76  func (s *agentSuiteV1) TestGetEntitiesNotFound(c *gc.C) {
    77  	s.testGetEntitiesNotFoundV0(c, s.newAPI(c))
    78  }
    79  
    80  func (s *agentSuiteV1) TestSetPasswords(c *gc.C) {
    81  	s.testSetPasswordsV0(c, s.newAPI(c))
    82  }
    83  
    84  func (s *agentSuiteV1) TestSetPasswordsShort(c *gc.C) {
    85  	s.testSetPasswordsShortV0(c, s.newAPI(c))
    86  }
    87  
    88  func (s *agentSuiteV1) newAPI(c *gc.C) *agent.AgentAPIV1 {
    89  	api, err := agent.NewAgentAPIV1(s.State, s.resources, s.authorizer)
    90  	c.Assert(err, jc.ErrorIsNil)
    91  	return api
    92  }