github.com/v2fly/v2ray-core/v4@v4.45.2/proxy/blackhole/blackhole_test.go (about)

     1  package blackhole_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/v2fly/v2ray-core/v4/common"
     8  	"github.com/v2fly/v2ray-core/v4/common/buf"
     9  	"github.com/v2fly/v2ray-core/v4/common/serial"
    10  	"github.com/v2fly/v2ray-core/v4/proxy/blackhole"
    11  	"github.com/v2fly/v2ray-core/v4/transport"
    12  	"github.com/v2fly/v2ray-core/v4/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  	readerError := make(chan error)
    24  	var mb buf.MultiBuffer
    25  	go func() {
    26  		b, e := reader.ReadMultiBuffer()
    27  		mb = b
    28  		readerError <- 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(<-readerError)
    37  	if mb.IsEmpty() {
    38  		t.Error("expect http response, but nothing")
    39  	}
    40  }