Skip to content

Commit

Permalink
test: add JSON serialization tests for some new non-native golang int…
Browse files Browse the repository at this point in the history
…erfaces
  • Loading branch information
jwise committed Mar 28, 2023
1 parent bf2389d commit 810c51d
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,49 @@ func TestEventMarshalJSON(t *testing.T) {
}}
event.StartTime = time.Unix(7, 0).UTC()
event.Timestamp = time.Unix(14, 0).UTC()
event.DebugMeta = &DebugMeta{
SdkInfo: &DebugMetaSdkInfo{
SdkName: "test",
VersionMajor: 1,
VersionMinor: 2,
VersionPatchlevel: 3,
},
Images: []DebugMetaImage{
{
Type: "macho",
DebugID: "12345",
CodeFile: "foo.dylib",
ImageAddr: "0xabcd0000",
},
},
}
event.Exception = []Exception{
{
Stacktrace: &Stacktrace{
Frames: []Frame{
{
Platform: "native",
StackStart: true,
Filename: "foo.m",
Lineno: 35,
InstructionAddr: "0xabcdef01",
},
},
},
},
}

got, err := json.Marshal(event)
if err != nil {
t.Fatal(err)
}

// Non-transaction event should not have fields Spans and StartTime
want := `{"sdk":{},"user":{},"timestamp":"1970-01-01T00:00:14Z"}`
want := `{"sdk":{},"user":{},` +
`"exception":[{"stacktrace":{"frames":[{"filename":"foo.m","lineno":35,"instruction_addr":"0xabcdef01","platform":"native","stack_start":true}]}}],` +
`"debug_meta":{"sdk_info":{"sdk_name":"test","version_major":1,"version_minor":2,"version_patchlevel":3},` +
`"images":[{"type":"macho","image_addr":"0xabcd0000","debug_id":"12345","code_file":"foo.dylib"}]},` +
`"timestamp":"1970-01-01T00:00:14Z"}`

if diff := cmp.Diff(want, string(got)); diff != "" {
t.Errorf("Event mismatch (-want +got):\n%s", diff)
Expand Down

0 comments on commit 810c51d

Please sign in to comment.