func (*ScaryConnectSuite) TestEntityUnknownLife(c *gc.C) { // "random" failure case stub := &testing.Stub{} expectConn := &mockConn{stub: stub} apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) { return expectConn, nil } entity := names.NewServiceTag("omg") connect := func() (api.Connection, error) { return apicaller.ScaryConnect(&mockAgent{ stub: stub, model: coretesting.ModelTag, entity: entity, }, apiOpen) } conn, err := lifeTest(c, stub, apiagent.Life("zombie"), connect) c.Check(conn, gc.IsNil) c.Check(err, gc.ErrorMatches, `unknown life value "zombie"`) stub.CheckCalls(c, []testing.StubCall{{ FuncName: "Life", Args: []interface{}{entity}, }, { FuncName: "Close", }}) }
func (s *FacadeSuite) TestLifeUnknown(c *gc.C) { result := params.AgentGetEntitiesResult{ Life: "revenant", } life, err := testLifeAPIResult(c, result) c.Check(err, gc.ErrorMatches, `unknown life value "revenant"`) c.Check(life, gc.Equals, agent.Life("")) }
func (s *FacadeSuite) TestLifeErrUnauthorized(c *gc.C) { result := params.AgentGetEntitiesResult{ Error: ¶ms.Error{Code: params.CodeUnauthorized}, } life, err := testLifeAPIResult(c, result) c.Check(err, gc.Equals, agent.ErrDenied) c.Check(life, gc.Equals, agent.Life("")) }
func (s *FacadeSuite) TestLifeRandomError(c *gc.C) { result := params.AgentGetEntitiesResult{ Error: ¶ms.Error{Message: "squish"}, } life, err := testLifeAPIResult(c, result) c.Check(err, gc.ErrorMatches, "squish") c.Check(life, gc.Equals, agent.Life("")) }
func (s *FacadeSuite) TestLifeNoResult(c *gc.C) { result := params.AgentGetEntitiesResults{} facade, err := agent.NewConnFacade(lifeChecker(c, result)) c.Assert(err, jc.ErrorIsNil) life, err := facade.Life(names.NewApplicationTag("omg")) c.Check(err, gc.ErrorMatches, "expected 1 result, got 0") c.Check(life, gc.Equals, agent.Life("")) }
func (s *FacadeSuite) TestLifeCallError(c *gc.C) { apiCaller := apiCaller(c, func(request string, arg, _ interface{}) error { c.Check(request, gc.Equals, "GetEntities") c.Check(arg, jc.DeepEquals, params.Entities{ Entities: []params.Entity{{ Tag: "application-omg", }}, }) return errors.New("splat") }) facade, err := agent.NewConnFacade(apiCaller) c.Assert(err, jc.ErrorIsNil) life, err := facade.Life(names.NewApplicationTag("omg")) c.Check(err, gc.ErrorMatches, "splat") c.Check(life, gc.Equals, agent.Life("")) }