func (me *testMyMarshaller) EncodeReport(fn interface{}, report *dingo.Report) (b []byte, err error) { bs := [][]byte{} // encode returns if report.OK() { bMsg, _ := json.Marshal(report.Return()[0]) bCount, _ := json.Marshal(report.Return()[1]) bs = append(bs, bMsg, bCount) } // encode status bStatus, _ := json.Marshal(report.Status()) // encode error bError, _ := json.Marshal(report.Error()) // encode option bOpt, _ := json.Marshal(report.Option()) bs = append(bs, bStatus, bError, bOpt) return dingo.ComposeBytes(report.H, bs) }
func TestReportMarshal(t *testing.T) { ass := assert.New(t) body, err := json.Marshal(&dingo.Report{ H: dingo.NewHeader("test_id", "test_name"), P: &dingo.ReportPayload{ S: 101, E: &dingo.Error{102, "test error"}, O: dingo.DefaultOption().IgnoreReport(true).MonitorProgress(true), R: nil, }, }) ass.Nil(err) var r dingo.Report err = json.Unmarshal(body, &r) ass.Nil(err) if err == nil { ass.Equal(int16(101), r.Status()) ass.Equal("test_id", r.ID()) ass.Equal(int32(102), r.Error().Code()) ass.Equal("test error", r.Error().Msg()) ass.Equal(true, r.Option().GetIgnoreReport()) ass.Equal(true, r.Option().GetMonitorProgress()) } }