blackhole_test.go 963 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package blackhole_test
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/v2fly/v2ray-core/v4/common"
  6. "github.com/v2fly/v2ray-core/v4/common/buf"
  7. "github.com/v2fly/v2ray-core/v4/common/serial"
  8. "github.com/v2fly/v2ray-core/v4/proxy/blackhole"
  9. "github.com/v2fly/v2ray-core/v4/transport"
  10. "github.com/v2fly/v2ray-core/v4/transport/pipe"
  11. )
  12. func TestBlackHoleHTTPResponse(t *testing.T) {
  13. handler, err := blackhole.New(context.Background(), &blackhole.Config{
  14. Response: serial.ToTypedMessage(&blackhole.HTTPResponse{}),
  15. })
  16. common.Must(err)
  17. reader, writer := pipe.New(pipe.WithoutSizeLimit())
  18. var readerError = make(chan error)
  19. var mb buf.MultiBuffer
  20. go func() {
  21. b, e := reader.ReadMultiBuffer()
  22. mb = b
  23. readerError <- e
  24. }()
  25. link := transport.Link{
  26. Reader: reader,
  27. Writer: writer,
  28. }
  29. common.Must(handler.Process(context.Background(), &link, nil))
  30. common.Must(<-readerError)
  31. if mb.IsEmpty() {
  32. t.Error("expect http response, but nothing")
  33. }
  34. }