github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/stacktrace/capture_test.go (about) 1 package stacktrace 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func captureFunc() Stacktrace { 9 return Capture(0) 10 } 11 12 func TestCaptureTestFunc(t *testing.T) { 13 stack := captureFunc() 14 15 if len(stack.Frames) == 0 { 16 t.Fatal("expected stack frames to be returned") 17 } 18 19 // the first frame is the caller 20 frame := stack.Frames[0] 21 if expected := "captureFunc"; frame.Function != expected { 22 t.Fatalf("expteced function %q but recevied %q", expected, frame.Function) 23 } 24 expected := "/runc/libcontainer/stacktrace" 25 if !strings.HasSuffix(frame.Package, expected) { 26 t.Fatalf("expected package %q but received %q", expected, frame.Package) 27 } 28 if expected := "capture_test.go"; frame.File != expected { 29 t.Fatalf("expected file %q but received %q", expected, frame.File) 30 } 31 }