package testutil
import "cloud.google.com/go/internal/testutil"
Package testutil contains helper functions for writing tests.
Index ¶
- func Diff(x, y interface{}, opts ...cmp.Option) string
- func Equal(x, y interface{}, opts ...cmp.Option) bool
- func IgnoreUnexported(typs ...interface{}) cmp.Option
- func ProjID() string
- func TokenSource(ctx context.Context, scopes ...string) oauth2.TokenSource
- func TokenSourceEnv(ctx context.Context, envVar string, scopes ...string) oauth2.TokenSource
- type Server
- func NewServer(opts ...grpc.ServerOption) (*Server, error)
- func (s *Server) Close()
- func (s *Server) Start()
- type UIDSpace
Functions ¶
func Diff ¶
Diff reports the differences between two values. Diff(x, y) == "" iff Equal(x, y).
func Equal ¶
Equal tests two values for equality.
func IgnoreUnexported ¶
IgnoreUnexported returns an Option that only ignores the immediate unexported fields of a struct, including anonymous fields of unexported types. In particular, unexported fields within the struct's exported fields of struct types, including anonymous fields, will not be ignored unless the type of the field itself is also passed to IgnoreUnexported.
func ProjID ¶
func ProjID() string
ProjID returns the project ID to use in integration tests, or the empty string if none is configured.
func TokenSource ¶
func TokenSource(ctx context.Context, scopes ...string) oauth2.TokenSource
TokenSource returns the OAuth2 token source to use in integration tests, or nil if none is configured. It uses the standard environment variable for tests in this repo.
func TokenSourceEnv ¶
TokenSourceEnv returns the OAuth2 token source to use in integration tests. or nil if none is configured. It tries to get credentials from the filename in the environment variable envVar. If the environment variable is unset, TokenSourceEnv will try to find 'Application Default Credentials'. Else, TokenSourceEnv will return nil. TokenSourceEnv will log.Fatal if the token source is specified but missing or invalid.
Types ¶
type Server ¶
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()) ...
func NewServer ¶
func NewServer(opts ...grpc.ServerOption) (*Server, error)
NewServer creates a new Server. The Server will be listening for gRPC connections at the address named by the Addr field, without TLS.
func (*Server) Close ¶
func (s *Server) Close()
Close shuts down the server.
func (*Server) Start ¶
func (s *Server) Start()
Start causes the server to start accepting incoming connections. Call Start after registering handlers.
type UIDSpace ¶
A UIDSpace manages a set of unique IDs distinguished by a prefix.
func NewUIDSpace ¶
func NewUIDSpaceSep ¶
func (*UIDSpace) New ¶
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 sep.
func (*UIDSpace) Older ¶
Older reports whether uid was created by m and has a timestamp older than the current time by at least d.
func (*UIDSpace) Timestamp ¶
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.
Source Files ¶
cmp.go context.go server.go unique.go
- Version
- v0.16.0
- Published
- Nov 1, 2017
- Platform
- darwin/amd64
- Imports
- 19 packages
- Last checked
- 26 minutes ago –
Tools for package owners.