github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/stacktrace_test.go (about) 1 package internal 2 3 import ( 4 "encoding/json" 5 "testing" 6 ) 7 8 func TestGetStackTrace(t *testing.T) { 9 stack := GetStackTrace(0) 10 js, err := json.Marshal(stack) 11 if nil != err { 12 t.Fatal(err) 13 } 14 if nil == js { 15 t.Fatal(string(js)) 16 } 17 } 18 19 func TestLongStackTrace(t *testing.T) { 20 st := StackTrace(make([]uintptr, maxStackTraceFrames+20)) 21 js, err := json.Marshal(st) 22 if nil != err { 23 t.Fatal(err) 24 } 25 expect := `[ 26 {},{},{},{},{},{},{},{},{},{}, 27 {},{},{},{},{},{},{},{},{},{}, 28 {},{},{},{},{},{},{},{},{},{}, 29 {},{},{},{},{},{},{},{},{},{}, 30 {},{},{},{},{},{},{},{},{},{}, 31 {},{},{},{},{},{},{},{},{},{}, 32 {},{},{},{},{},{},{},{},{},{}, 33 {},{},{},{},{},{},{},{},{},{}, 34 {},{},{},{},{},{},{},{},{},{}, 35 {},{},{},{},{},{},{},{},{},{} 36 ]` 37 if string(js) != CompactJSONString(expect) { 38 t.Error(string(js)) 39 } 40 }