From ae2def146399745a8dba5113d5e1b57292a258e8 Mon Sep 17 00:00:00 2001 From: GrĂ©goire DuchĂȘne Date: Sun, 14 Feb 2021 12:45:01 +0000 Subject: Add README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb07501 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +`pipeln` implements a trivial type, `PipeListenerDialer`, that can be +used both as a `net.Listener` and as a dialer. It uses `net.Pipe` to +connect server and clients so that testing client-server communication +becomes easier. + +Several dialer methods are available, and happen (as there is no +`net.Dialer` interface) to be compatible with both `net.Transport` and +`grpc.WithContextDialer`. + +For instance: + +```go +func TestHTTP(t *testing.T) { + ln := pipeln.New("test:80") + + srv := http.Server{} + go srv.Serve(ln) + + client := http.Client{Transport: &http.Transport{Dial: ln.Dial}} + + // ... +} + +func TestGRPC(t *testing.T) { + ln := pipeln.New("test") + + srv := grpc.NewServer() + go srv.Serve(ln) + + client, _ := grpc.Dial("test", grpc.WithContextDialer(ln.DialContextAddr), grpc.WithInsecure()) + + // ... +} +``` -- cgit v1.2.3-70-g09d2