Documentation ¶
Overview ¶
Package kt provides common utilities for Kivik tests.
Index ¶
- Constants
- Variables
- func Body(str string, args ...interface{}) io.ReadCloser
- func DSN(t *testing.T) string
- func GetClient(t *testing.T) *kivik.Client
- func GetNoAuthClient(t *testing.T) *kivik.Client
- func NoAuthDSN(t *testing.T) string
- func Register(name string, fn testFunc)
- func Retry(fn func() error) error
- func RunSubtests(ctx *Context)
- func TestDBName(t *testing.T) string
- type Context
- func (c *Context) Bool(key string) bool
- func (c *Context) CheckError(err error) (match bool, success bool)
- func (c *Context) Child(t *testing.T) *Context
- func (c *Context) DestroyDB(name string)
- func (c *Context) Errorf(format string, args ...interface{})
- func (c *Context) Fatalf(format string, args ...interface{})
- func (c *Context) Int(key string) int
- func (c *Context) IntSlice(key string) []int
- func (c *Context) Interface(key string) interface{}
- func (c *Context) IsExpected(err error) bool
- func (c *Context) IsExpectedSuccess(err error) bool
- func (c *Context) IsSet(key string) bool
- func (c *Context) IsSuccess(err error) bool
- func (c *Context) Logf(format string, args ...interface{})
- func (c *Context) MustBeSet(key string)
- func (c *Context) MustBool(key string) bool
- func (c *Context) MustInt(key string) int
- func (c *Context) MustIntSlice(key string) []int
- func (c *Context) MustInterface(key string) interface{}
- func (c *Context) MustString(key string) string
- func (c *Context) MustStringSlice(key string) []string
- func (c *Context) Options(key string) map[string]interface{}
- func (c *Context) Parallel()
- func (c *Context) Run(name string, fn testFunc)
- func (c *Context) RunAdmin(fn testFunc)
- func (c *Context) RunNoAuth(fn testFunc)
- func (c *Context) RunRO(fn testFunc)
- func (c *Context) RunRW(fn testFunc)
- func (c *Context) Skip()
- func (c *Context) Skipf(format string, args ...interface{})
- func (c *Context) String(key string) string
- func (c *Context) StringSlice(key string) []string
- func (c *Context) TestDB() string
- func (c *Context) TestDBName() string
- type SuiteConfig
- func (c SuiteConfig) Bool(t *testing.T, key string) bool
- func (c SuiteConfig) Int(t *testing.T, key string) int
- func (c SuiteConfig) Interface(t *testing.T, key string) interface{}
- func (c SuiteConfig) Skip(t *testing.T)
- func (c SuiteConfig) String(t *testing.T, key string) string
- func (c SuiteConfig) StringSlice(t *testing.T, key string) []string
Constants ¶
const TestDBPrefix = "kivik$"
TestDBPrefix is used to prefix temporary database names during tests.
Variables ¶
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 Body ¶
func Body(str string, args ...interface{}) io.ReadCloser
Body turns a string into a read closer, useful as a request or attachment body.
func GetNoAuthClient ¶
GetNoAuthClient returns an unauthenticated connection to a CouchDB client, for testing.
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 ¶
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 ¶
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 privileges. Admin *kivik.Client // NoAuth isa client connection with no authentication. NoAuth *kivik.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) CheckError ¶
CheckError compares the error's status code with that expected.
func (*Context) IsExpected ¶
IsExpected checks the error against the expected status, and returns true if they match.
func (*Context) IsExpectedSuccess ¶
IsExpectedSuccess combines IsExpected() and IsSuccess(), returning true only if there is no error, and no error was expected.
func (*Context) IsSuccess ¶
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) MustIntSlice ¶
MustIntSlice returns a []int, or fails if the value is unset.
func (*Context) MustInterface ¶
MustInterface returns an interface{} from the config, or fails if the value is unset.
func (*Context) MustString ¶
MustString returns a string from config, or fails if the value is unset.
func (*Context) MustStringSlice ¶
MustStringSlice returns a string slice, or fails if the value is unset.
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) StringSlice ¶
StringSlice returns a string slice from the config.
func (*Context) TestDBName ¶
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) 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.