testutil

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil contains helper functions for writing tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProjID

func ProjID() string

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

func TestIteratorNext

func TestIteratorNext(want interface{}, done error, next func() (interface{}, error)) (string, bool)

TestIteratorNext tests the Next method of a standard client iterator (see https://github.com/GoogleCloudPlatform/gcloud-golang/wiki/Iterator-Guidelines).

This function assumes that an iterator has already been created, and that the underlying sequence to be iterated over already exists. want should be a slice that contains the elements of this sequence. It must contain at least one element.

done is the special error value that signals that the iterator has provided all the items.

next is a function that returns the result of calling Next on the iterator. It can usually be defined as

func() (interface{}, error) { return iter.Next() }

TestIteratorNext checks that the iterator returns all the elements of want in order, followed by (zero, done). It also confirms that subsequent calls to next also return (zero, done).

On success, TestIteratorNext returns ("", true). On failure, it returns a suitable error message and false.

func TestIteratorNextPageExact

func TestIteratorNextPageExact(want interface{}, done error, defaultPageSize int32, newIter func() PagingIterator, nextPage func(PagingIterator) (interface{}, error)) (string, bool)

TestIteratorNextPageExact tests the NextPage method of a standard client iterator with paging (see PagingIterator).

This function assumes that the underlying sequence to be iterated over already exists. want should be a slice that contains the elements of this sequence. It must contain at least three elements, in order to test non-trivial paging behavior.

done is the special error value that signals that the iterator has provided all the items.

defaultPageSize is the page size to use when the user has not called SetPageSize, or calls it with a value <= 0.

newIter should return a new iterator each time it is called.

nextPage should return the result of calling NextPage on the iterator. It can usually be defined as

func(i testutil.PagingIterator) (interface{}, error) { return i.(*<iteratorType>).NextPage() }

TestIteratorNextPageExact checks that the iterator returns all the elements of want in order, divided into pages of the exactly the right size. It confirms that if the last page is partial, done is returned along with it, and in any case, done is returned subsequently along with a zero-length slice.

On success, TestIteratorNextPageExact returns ("", true). On failure, it returns a suitable error message and false.

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. TokenSource will log.Fatal if the token source is specified but missing or invalid.

Types

type PagingIterator

type PagingIterator interface {
	SetPageSize(int32)
	SetPageToken(string)
	NextPageToken() string
}

PagingIterator describes the standard client iterator pattern with paging as best as possible in Go. See https://github.com/GoogleCloudPlatform/gcloud-golang/wiki/Iterator-Guidelines.

type Server

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)
....
srv.Start()

Clients should connect to the server with no security:

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

func NewServer

func NewServer() (*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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL