Skip to content

Commit

Permalink
test: add individual tests for new stacktrace and debugmeta interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jwise committed Mar 28, 2023
1 parent bf2389d commit 8b47c36
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
55 changes: 55 additions & 0 deletions interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,61 @@ func TestEventMarshalJSON(t *testing.T) {
}
}

func TestEventWithDebugMetaMarshalJSON(t *testing.T) {
event := NewEvent()
event.DebugMeta = &DebugMeta{
SdkInfo: &DebugMetaSdkInfo{
SdkName: "test",
VersionMajor: 1,
VersionMinor: 2,
VersionPatchlevel: 3,
},
Images: []DebugMetaImage{
{
Type: "macho",
ImageAddr: "0xabcd0000",
ImageSize: 32768,
DebugID: "42DB5B96-5144-4079-BE09-45E2142CA3E5",
DebugFile: "foo.dSYM",
CodeID: "A7AF6477-9130-4EB7-ADFE-AD0F57001DBD",
CodeFile: "foo.dylib",
ImageVmaddr: "0x0",
Arch: "arm64",
},
{
Type: "proguard",
UUID: "982E62D4-6493-4E43-864B-6523C79C7064",
},
},
}

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

want := `{"sdk":{},"user":{},` +
`"debug_meta":{` +
`"sdk_info":{"sdk_name":"test","version_major":1,"version_minor":2,"version_patchlevel":3},` +
`"images":[` +
`{"type":"macho",` +
`"image_addr":"0xabcd0000",` +
`"image_size":32768,` +
`"debug_id":"42DB5B96-5144-4079-BE09-45E2142CA3E5",` +
`"debug_file":"foo.dSYM",` +
`"code_id":"A7AF6477-9130-4EB7-ADFE-AD0F57001DBD",` +
`"code_file":"foo.dylib",` +
`"image_vmaddr":"0x0",` +
`"arch":"arm64"` +
`},` +
`{"type":"proguard","uuid":"982E62D4-6493-4E43-864B-6523C79C7064"}` +
`]}}`

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

func TestMechanismMarshalJSON(t *testing.T) {
mechanism := &Mechanism{
Type: "some type",
Expand Down
73 changes: 73 additions & 0 deletions stacktrace_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sentry

import (
"encoding/json"
"errors"
"testing"

Expand Down Expand Up @@ -169,3 +170,75 @@ func TestExtractXErrorsPC(t *testing.T) {
t.Errorf("got %#v, want nil", got)
}
}

func TestEventWithExceptionStacktraceMarshalJSON(t *testing.T) {
event := NewEvent()
event.Exception = []Exception{
{
Stacktrace: &Stacktrace{
Frames: []Frame{
{
Function: "gofunc",
Symbol: "gosym",
Module: "gopkg/gopath",
Filename: "foo.go",
AbsPath: "/something/foo.go",
Lineno: 35,
Colno: 72,
PreContext: []string{"pre", "context"},
ContextLine: "contextline",
PostContext: []string{"post", "context"},
InApp: true,
Vars: map[string]interface{}{
"foostr": "bar",
"fooint": 25,
},
},
{
Symbol: "nativesym",
Package: "my.dylib",
InstructionAddr: "0xabcd0010",
AddrMode: "abs",
SymbolAddr: "0xabcd0000",
ImageAddr: "0xabc00000",
Platform: "native",
StackStart: false,
},
},
},
},
}

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

want := `{"sdk":{},"user":{},` +
`"exception":[{"stacktrace":{"frames":[` +
`{"function":"gofunc",` +
`"symbol":"gosym",` +
`"module":"gopkg/gopath",` +
`"filename":"foo.go",` +
`"abs_path":"/something/foo.go",` +
`"lineno":35,` +
`"colno":72,` +
`"pre_context":["pre","context"],` +
`"context_line":"contextline",` +
`"post_context":["post","context"],` +
`"in_app":true,` +
`"vars":{"fooint":25,"foostr":"bar"}` +
`},{` +
`"symbol":"nativesym",` +
`"package":"my.dylib",` +
`"instruction_addr":"0xabcd0010",` +
`"addr_mode":"abs",` +
`"symbol_addr":"0xabcd0000",` +
`"image_addr":"0xabc00000",` +
`"platform":"native"` +
`}]}}]}`

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

0 comments on commit 8b47c36

Please sign in to comment.