2014-10-23 07:10:51 +08:00
|
|
|
package stacktrace
|
|
|
|
|
2016-02-29 22:45:33 +08:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
2014-10-23 07:10:51 +08:00
|
|
|
|
|
|
|
func captureFunc() Stacktrace {
|
|
|
|
return Capture(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCaptureTestFunc(t *testing.T) {
|
|
|
|
stack := captureFunc()
|
|
|
|
|
|
|
|
if len(stack.Frames) == 0 {
|
|
|
|
t.Fatal("expected stack frames to be returned")
|
|
|
|
}
|
|
|
|
|
|
|
|
// the first frame is the caller
|
|
|
|
frame := stack.Frames[0]
|
|
|
|
if expected := "captureFunc"; frame.Function != expected {
|
2016-11-30 13:27:50 +08:00
|
|
|
t.Fatalf("expected function %q but recevied %q", expected, frame.Function)
|
2014-10-23 07:10:51 +08:00
|
|
|
}
|
2016-08-16 18:29:00 +08:00
|
|
|
expected := "/runc/libcontainer/stacktrace"
|
2016-02-29 22:45:33 +08:00
|
|
|
if !strings.HasSuffix(frame.Package, expected) {
|
2014-10-23 07:10:51 +08:00
|
|
|
t.Fatalf("expected package %q but received %q", expected, frame.Package)
|
|
|
|
}
|
|
|
|
if expected := "capture_test.go"; frame.File != expected {
|
|
|
|
t.Fatalf("expected file %q but received %q", expected, frame.File)
|
|
|
|
}
|
|
|
|
}
|