Package testutil contains helper functions for writing tests.
ProjID returns the project ID to use in integration tests, or the empty string if none is configured.
TokenSource returns the OAuth2 token source to use in integration tests, or nil if none is configured. If the environment variable is unset, TokenSource will try to find 'Application Default Credentials'. Else, TokenSource will return nil. TokenSource will log.Fatal if the token source is specified but missing or invalid.
A Server is an in-process gRPC server, listening on a system-chosen port on the local loopback interface. Servers are for testing only and are not intended to be used in production code.
To create a server, make a new Server, register your handlers, then call Start:
srv, err := NewServer() ... mypb.RegisterMyServiceServer(srv.Gsrv, &myHandler) .... srv.Start()
Clients should connect to the server with no security:
conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure()) ...
NewServer creates a new Server. The Server will be listening for gRPC connections at the address named by the Addr field, without TLS.
Close shuts down the server.
Start causes the server to start accepting incoming connections. Call Start after registering handlers.
A UIDSpace manages a set of unique IDs distinguished by a prefix.
New generates a new unique ID . The ID consists of the UIDSpace's prefix, a timestamp, and a counter value. All unique IDs generated in the same test execution will have the same timestamp.
Aside from the characters in the prefix, IDs contain only letters, numbers and hyphens.
Older reports whether uid was created by m and has a timestamp older than the current time by at least d.
Timestamp extracts the timestamp of uid, which must have been generated by s. The second return value is true on success, false if there was a problem.