context_test.go 629 B

12345678910111213141516171819202122232425262728293031323334
  1. package core_test
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/v2fly/v2ray-core/v4"
  6. _ "unsafe"
  7. )
  8. func TestFromContextPanic(t *testing.T) {
  9. defer func() {
  10. r := recover()
  11. if r == nil {
  12. t.Error("expect panic, but nil")
  13. }
  14. }()
  15. MustFromContext(context.Background())
  16. }
  17. //go:linkname mustToContextForced github.com/v2fly/v2ray-core/v4.mustToContext
  18. func mustToContextForced(ctx context.Context, v *Instance) context.Context
  19. func TestToContextPanic(t *testing.T) {
  20. defer func() {
  21. r := recover()
  22. if r == nil {
  23. t.Error("expect panic, but nil")
  24. }
  25. }()
  26. mustToContextForced(context.Background(), &Instance{})
  27. }