Skip to content

Instantly share code, notes, and snippets.

@sugamon
Created December 24, 2019 02:09
Show Gist options
  • Save sugamon/35dd66a0534b442f963dc8ac01c78f39 to your computer and use it in GitHub Desktop.
Save sugamon/35dd66a0534b442f963dc8ac01c78f39 to your computer and use it in GitHub Desktop.
pstest sample
ctx := context.Background()
// Start a fake server running locally.
srv := pstest.NewServer()
defer srv.Close()
// Connect to the server without using TLS.
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())
if err != nil {
// TODO: Handle error.
}
defer conn.Close()
// Use the connection when creating a pubsub client.
client, err := pubsub.NewClient(ctx, "project", option.WithGRPCConn(conn))
if err != nil {
// TODO: Handle error.
}
defer client.Close()
_ = client // TODO: Use the client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment