testing

package
v0.0.0-...-6b9f808 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package testing provides support functions for testing iterators conforming to the standard pattern. See package google.golang.org/api/iterator and https://github.com/GoogleCloudPlatform/gcloud-golang/wiki/Iterator-Guidelines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestIterator

func TestIterator(want interface{}, create func() interface{}, next func(interface{}) (interface{}, error)) (string, bool)

TestIterator tests the Next method of a standard iterator. It assumes that the underlying sequence to be iterated over already exists.

The want argument should be a slice that contains the elements of this sequence. It may be an empty slice, but it must not be the nil interface value. The elements must be comparable with reflect.DeepEqual.

The create function should create and return a new iterator. It will typically look like

func() interface{} { return client.Items(ctx) }

The next function takes the return value of create and should return the result of calling Next on the iterator. It can usually be defined as

func(it interface{}) (interface{}, error) { return it.(*ItemIterator).Next() }

TestIterator 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).

If the iterator implements the method

PageInfo() *iterator.PageInfo

then exact pagination with iterator.Pager is also tested. Pagination testing will be more informative if the want slice contains at least three elements.

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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