title: Mocking `peer` while unit testing gRPC with bufconn
body: <p>I have unidirectional (both client- and server-) streaming gRPC methods implemented in my golang server. I came across <a href="https://pkg.go.dev/google.golang.org/grpc@v1.37.0/test/bufconn" rel="nofollow noreferrer"><code>bufconn</code></a> which enables me to creates my server via in-memory connections in my tests. However, I have logic in my method where I check the peer's address, it always returns &quot;bufconn&quot;. I do rely on the peer to provide the IP address along with its port, but I can't really achieve that using bufconn.</p>
  <ol>
  <li>What is a canonical (or preferred) way to test gRPC streaming calls in golang?</li>
  <li>Is it considered an anti-pattern to rely on peer information in the context?</li>
  </ol>