go: cloud.google.com/go/internal/testutil Index | Files

package testutil

import "cloud.google.com/go/internal/testutil"

Package testutil contains helper functions for writing tests.


Package Files

cmp.go context.go go18.go server.go

func Diff Uses

func Diff(x, y interface{}, opts ...cmp.Option) string

Diff reports the differences between two values. Diff(x, y) == "" iff Equal(x, y).

func Equal Uses

func Equal(x, y interface{}, opts ...cmp.Option) bool

Equal tests two values for equality.

func JWTConfig Uses

func JWTConfig() (*jwt.Config, error)

JWTConfig reads the JSON private key file whose name is in the default environment variable, and returns the jwt.Config it contains. It ignores scopes. If the environment variable is empty, it returns (nil, nil).

func PageBounds Uses

func PageBounds(pageSize int, pageToken string, length int) (from, to int, nextPageToken string, err error)

PageBounds converts an incoming page size and token from an RPC request into slice bounds and the outgoing next-page token.

PageBounds assumes that the complete, unpaginated list of items exists as a single slice. In addition to the page size and token, PageBounds needs the length of that slice.

PageBounds's first two return values should be used to construct a sub-slice of the complete, unpaginated slice. E.g. if the complete slice is s, then s[from:to] is the desired page. Its third return value should be set as the NextPageToken field of the RPC response.

func ProjID Uses

func ProjID() string

ProjID returns the project ID to use in integration tests, or the empty string if none is configured.

func TokenSource Uses

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 Uses

func TokenSourceEnv(ctx context.Context, envVar string, scopes ...string) oauth2.TokenSource

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.

type Server Uses

type Server struct {
    Addr string

    Gsrv *grpc.Server
    // contains filtered or unexported fields

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)

Clients should connect to the server with no security:

conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure())

func NewServer Uses

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 Uses

func (s *Server) Close()

Close shuts down the server.

func (*Server) Start Uses

func (s *Server) Start()

Start causes the server to start accepting incoming connections. Call Start after registering handlers.

type TestExporter Uses

type TestExporter struct {
    Spans []*trace.SpanData
    Stats chan *view.Data

func NewTestExporter Uses

func NewTestExporter() *TestExporter

func (*TestExporter) ExportSpan Uses

func (te *TestExporter) ExportSpan(s *trace.SpanData)

func (*TestExporter) ExportView Uses

func (te *TestExporter) ExportView(vd *view.Data)

func (*TestExporter) Unregister Uses

func (te *TestExporter) Unregister()

Package testutil imports 21 packages (graph) and is imported by 2 packages. Updated 2018-06-22. Refresh now. Tools for package owners.