aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: f1fc3e4e941b467965da9ea7cae06bb87ccc0757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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{DialContext: ln.DialContext}}

	// ...
}

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())

	// ...
}
```