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