Test a gRPC Server and Client

Now that we’ve finished our gRPC server, we need some tests to check that our client and server work like we expect. We’ve already tested the details of our log’s library implementation in the library, so the tests we’re writing here are at a higher level and focus on ensuring that everything’s hooked up properly between the gRPC and library bits and that our gRPC client and server can communicate.

In the grpc directory, create a server_test.go file, and add the following code that will set up your test:

 package​ server
 
 import​ (
 "context"
 "io/ioutil"
 "net"
 "testing"
 
 "github.com/stretchr/testify/require"
  api ​"github.com/travisjeffery/proglog/api/v1" ...

Get Distributed Services with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.