kt

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: May 1, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package kt provides common utilities for Kivik tests.

Index

Constants

View Source
const TestDBPrefix = "kivik$"

TestDBPrefix is used to prefix temporary database names during tests.

Variables

View Source
var AllDocsIndex = kivik.Index{Name: "_all_docs", Type: "special",
	Definition: map[string]interface{}{"fields": []map[string]string{{"_id": "asc"}}}}

AllDocsIndex is the default index for _all_docs

Functions

func DSN

func DSN(t *testing.T) string

DSN returns a testing DSN from the environment.

func GetClient

func GetClient(t *testing.T) *kivik.Client

GetClient returns a connection to a CouchDB client, for testing.

func GetNoAuthClient

func GetNoAuthClient(t *testing.T) *kivik.Client

GetNoAuthClient returns an unauthenticated connection to a CouchDB client, for testing.

func NoAuthDSN

func NoAuthDSN(t *testing.T) string

NoAuthDSN returns a testing DSN with credentials stripped.

func Register

func Register(name string, fn testFunc)

Register registers a test to be run for the given test suite. rw should be true if the test writes to the database.

func Retry

func Retry(fn func() error) error

Retry will try an operation up to 3 times, in case of one of the following failures. All other failures are returned.

func RunSubtests

func RunSubtests(ctx *Context)

RunSubtests executes the requested suites of tests against the client.

func TestDBName

func TestDBName(t *testing.T) string

TestDBName generates a randomized string suitable for a database name for testing.

Types

type Context

type Context struct {
	// RW is true if we should run read-write tests.
	RW bool
	// Admin is a client connection with database admin priveleges.
	Admin *kivik.Client
	// CHTTPAdmin is a chttp connection with admin priveleges.
	CHTTPAdmin *chttp.Client
	// NoAuth isa client connection with no authentication.
	NoAuth *kivik.Client
	// CHTTPNoAuth is a chttp connection with no authentication.
	CHTTPNoAuth *chttp.Client
	// Config is the suite config
	Config SuiteConfig
	// T is the *testing.T value
	T *testing.T
}

Context is a collection of client connections with different security access.

func (*Context) Bool

func (c *Context) Bool(key string) bool

Bool returns a bool from the config.

func (*Context) CheckError

func (c *Context) CheckError(err error) (match bool, success bool)

CheckError compares the error's status code with that expected.

func (*Context) Child

func (c *Context) Child(t *testing.T) *Context

Child returns a shallow copy of itself with a new t.

func (*Context) Errorf

func (c *Context) Errorf(format string, args ...interface{})

Errorf is a wrapper around t.Errorf()

func (*Context) Fatalf

func (c *Context) Fatalf(format string, args ...interface{})

Fatalf is a wrapper around t.Fatalf()

func (*Context) Int

func (c *Context) Int(key string) int

Int returns an int from the config.

func (*Context) IntSlice

func (c *Context) IntSlice(key string) []int

IntSlice returns a []int from config.

func (*Context) Interface

func (c *Context) Interface(key string) interface{}

Interface returns the configuration value as an interface{}.

func (*Context) IsExpected

func (c *Context) IsExpected(err error) bool

IsExpected checks the error against the expected status, and returns true if they match.

func (*Context) IsExpectedSuccess

func (c *Context) IsExpectedSuccess(err error) bool

IsExpectedSuccess combines IsExpected() and IsSuccess(), returning true only if there is no error, and no error was expected.

func (*Context) IsSet

func (c *Context) IsSet(key string) bool

IsSet returns true if the value is set in the configuration.

func (*Context) IsSuccess

func (c *Context) IsSuccess(err error) bool

IsSuccess is similar to IsExpected, except for its return value. This method returns true if the expected status == 0, regardless of the error.

func (*Context) Logf

func (c *Context) Logf(format string, args ...interface{})

Logf is a wrapper around t.Logf()

func (*Context) MustBeSet

func (c *Context) MustBeSet(key string)

MustBeSet ends the test with a failure if the config key is not set.

func (*Context) MustBool

func (c *Context) MustBool(key string) bool

MustBool returns a bool, or fails if the value is unset.

func (*Context) MustInt

func (c *Context) MustInt(key string) int

MustInt returns an int from the config, or fails if the value is unset.

func (*Context) MustIntSlice

func (c *Context) MustIntSlice(key string) []int

MustIntSlice returns a []int, or fails if the value is unset.

func (*Context) MustInterface

func (c *Context) MustInterface(key string) interface{}

MustInterface returns an interface{} from the config, or fails if the value is unset.

func (*Context) MustString

func (c *Context) MustString(key string) string

MustString returns a string from config, or fails if the value is unset.

func (*Context) MustStringSlice

func (c *Context) MustStringSlice(key string) []string

MustStringSlice returns a string slice, or fails if the value is unset.

func (*Context) Options

func (c *Context) Options(key string) map[string]interface{}

Options returns an options map value.

func (*Context) Parallel

func (c *Context) Parallel()

Parallel is a wrapper around t.Parallel()

func (*Context) Run

func (c *Context) Run(name string, fn testFunc)

Run wraps t.Run()

func (*Context) RunAdmin

func (c *Context) RunAdmin(fn testFunc)

RunAdmin runs the test function iff c.Admin is set.

func (*Context) RunNoAuth

func (c *Context) RunNoAuth(fn testFunc)

RunNoAuth runs the test function iff c.NoAuth is set.

func (*Context) RunRO

func (c *Context) RunRO(fn testFunc)

RunRO runs the test function iff c.RW is false. Note that unlike RunRW, this does not start a new subtest. This should usually be run in conjunction with RunRW, to run only RO or RW tests, in situations where running both would be redundant.

func (*Context) RunRW

func (c *Context) RunRW(fn testFunc)

RunRW runs the test function iff c.RW is true.

func (*Context) Skip

func (c *Context) Skip()

Skip will skip the currently running test if configuration dictates.

func (*Context) Skipf

func (c *Context) Skipf(format string, args ...interface{})

Skipf is a wrapper around t.Skipf()

func (*Context) String

func (c *Context) String(key string) string

String returns a string from config.

func (*Context) StringSlice

func (c *Context) StringSlice(key string) []string

StringSlice returns a string slice from the config.

func (*Context) TestDB

func (c *Context) TestDB() string

TestDB creates a test database and returns its name.

func (*Context) TestDBName

func (c *Context) TestDBName() string

TestDBName generates a randomized string suitable for a database name for testing.

type SuiteConfig

type SuiteConfig map[string]interface{}

SuiteConfig represents the configuration for a test suite.

func (SuiteConfig) Bool

func (c SuiteConfig) Bool(t *testing.T, key string) bool

Bool returns the boolean value of the key.

func (SuiteConfig) Int

func (c SuiteConfig) Int(t *testing.T, key string) int

Int returns an int.

func (SuiteConfig) Interface

func (c SuiteConfig) Interface(t *testing.T, key string) interface{}

Interface returns the configuration value as an interface{}.

func (SuiteConfig) Skip

func (c SuiteConfig) Skip(t *testing.T)

Skip will skip the currently running test if configuration dictates.

func (SuiteConfig) String

func (c SuiteConfig) String(t *testing.T, key string) string

String returns a string.

func (SuiteConfig) StringSlice

func (c SuiteConfig) StringSlice(t *testing.T, key string) []string

StringSlice returns a string slice.

Jump to

Keyboard shortcuts

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