// API2Result converts the API result to a payload.Result. func API2Result(r PayloadResult) (payload.Result, error) { result := payload.Result{ NotFound: r.NotFound, } id, err := API2ID(r.Tag) if err != nil { return result, errors.Trace(err) } result.ID = id if r.Payload != nil { pl, err := api.API2Payload(*r.Payload) if err != nil { return result, errors.Trace(err) } result.Payload = &pl } if r.Error != nil { result.Error = common.RestoreError(r.Error) } return result, nil }
func (s *clientSuite) TestTrack(c *gc.C) { id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309" numStubCalls := 0 s.facade.FacadeCallFn = func(name string, args, response interface{}) error { numStubCalls++ c.Check(name, gc.Equals, "Track") typedResponse, ok := response.(*internal.PayloadResults) c.Assert(ok, gc.Equals, true) typedResponse.Results = []internal.PayloadResult{{ Entity: params.Entity{ Tag: names.NewPayloadTag(id).String(), }, Payload: nil, NotFound: false, Error: nil, }} return nil } pclient := client.NewUnitFacadeClient(s.facade) pl, err := api.API2Payload(s.payload) c.Assert(err, jc.ErrorIsNil) results, err := pclient.Track(pl.Payload) c.Assert(err, jc.ErrorIsNil) c.Check(numStubCalls, gc.Equals, 1) c.Check(results, jc.DeepEquals, []payload.Result{{ ID: id, Payload: nil, NotFound: false, Error: nil, }}) }
// Track stores a payload to be tracked in state. func (uf UnitFacade) Track(args internal.TrackArgs) (internal.PayloadResults, error) { logger.Debugf("tracking %d payloads from API", len(args.Payloads)) var r internal.PayloadResults for _, apiPayload := range args.Payloads { pl, err := api.API2Payload(apiPayload) if err != nil { return r, errors.Trace(err) } logger.Debugf("tracking payload from API: %#v", pl) id, err := uf.track(pl.Payload) res := internal.NewPayloadResult(id, err) r.Results = append(r.Results, res) } return r, nil }
func (s *publicSuite) TestListOkay(c *gc.C) { s.facade.FacadeCallFn = func(_ string, _, response interface{}) error { typedResponse, ok := response.(*api.EnvListResults) c.Assert(ok, gc.Equals, true) typedResponse.Results = append(typedResponse.Results, s.payload) return nil } pclient := client.NewPublicClient(s.facade) payloads, err := pclient.ListFull("a-tag", "a-application/0") c.Assert(err, jc.ErrorIsNil) expected, _ := api.API2Payload(s.payload) c.Check(payloads, jc.DeepEquals, []payload.FullPayloadInfo{ expected, }) }
// ListFull calls the List API server method. func (c PublicClient) ListFull(patterns ...string) ([]payload.FullPayloadInfo, error) { var result api.EnvListResults args := api.EnvListArgs{ Patterns: patterns, } if err := c.FacadeCall("List", &args, &result); err != nil { return nil, errors.Trace(err) } payloads := make([]payload.FullPayloadInfo, len(result.Results)) for i, apiInfo := range result.Results { payload, err := api.API2Payload(apiInfo) if err != nil { // We should never see this happen; we control the input safely. return nil, errors.Trace(err) } payloads[i] = payload } return payloads, nil }
func (s *clientSuite) TestList(c *gc.C) { id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309" responses := []interface{}{ &internal.PayloadResults{ Results: []internal.PayloadResult{{ Entity: params.Entity{ Tag: names.NewPayloadTag(id).String(), }, Payload: nil, NotFound: false, Error: nil, }}, }, &internal.PayloadResults{ Results: []internal.PayloadResult{{ Entity: params.Entity{ Tag: names.NewPayloadTag(id).String(), }, Payload: &s.payload, NotFound: false, Error: nil, }}, }, } s.facade.responses = append(s.facade.responses, responses...) pclient := client.NewUnitFacadeClient(s.facade) results, err := pclient.List("idfoo/bar") c.Assert(err, jc.ErrorIsNil) expected, err := api.API2Payload(s.payload) c.Assert(err, jc.ErrorIsNil) c.Check(results, jc.DeepEquals, []payload.Result{{ ID: id, Payload: &expected, NotFound: false, Error: nil, }}) s.stub.CheckCalls(c, []testing.StubCall{{ FuncName: "FacadeCall", Args: []interface{}{ "LookUp", &internal.LookUpArgs{ Args: []internal.LookUpArg{{ Name: "idfoo", ID: "bar", }}, }, responses[0], }, }, { FuncName: "FacadeCall", Args: []interface{}{ "List", ¶ms.Entities{ Entities: []params.Entity{{ Tag: names.NewPayloadTag(id).String(), }}, }, responses[1], }, }}) }