func api2results(rs internal.PayloadResults) ([]payload.Result, error) { var results []payload.Result for _, r := range rs.Results { result, err := internal.API2Result(r) if err != nil { // This should not happen; we safely control the result. return nil, errors.Trace(err) } results = append(results, result) } return results, nil }
func (internalHelpersSuite) TestAPI2ResultOkay(c *gc.C) { id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309" result, err := private.API2Result(private.PayloadResult{ Entity: params.Entity{ Tag: names.NewPayloadTag(id).String(), }, Payload: nil, NotFound: false, Error: nil, }) c.Assert(err, jc.ErrorIsNil) c.Check(result, jc.DeepEquals, payload.Result{ ID: id, Payload: nil, NotFound: false, Error: nil, }) }
func (internalHelpersSuite) TestAPI2ResultError(c *gc.C) { id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309" failure := errors.New("<failure>") result, err := private.API2Result(private.PayloadResult{ Entity: params.Entity{ Tag: names.NewPayloadTag(id).String(), }, Payload: nil, NotFound: false, Error: common.ServerError(failure), }) c.Assert(err, jc.ErrorIsNil) c.Check(result.Error.Error(), gc.Equals, failure.Error()) c.Check(result, jc.DeepEquals, payload.Result{ ID: id, Payload: nil, NotFound: false, Error: result.Error, // The actual error is checked above. }) }
func (internalHelpersSuite) TestAPI2ResultInfo(c *gc.C) { id := "ce5bc2a7-65d8-4800-8199-a7c3356ab309" result, err := private.API2Result(private.PayloadResult{ Entity: params.Entity{ Tag: names.NewPayloadTag(id).String(), }, NotFound: false, Error: nil, Payload: &api.Payload{ Class: "foobar", Type: "type", ID: "idfoo", Status: payload.StateRunning, Unit: "unit-a-service-0", Machine: "machine-1", }, }) c.Assert(err, jc.ErrorIsNil) c.Check(result, jc.DeepEquals, payload.Result{ ID: id, NotFound: false, Error: nil, Payload: &payload.FullPayloadInfo{ Payload: payload.Payload{ PayloadClass: charm.PayloadClass{ Name: "foobar", Type: "type", }, ID: "idfoo", Status: payload.StateRunning, Unit: "a-service/0", }, Machine: "1", }, }) }