Skip to content
Kivik mock driver to test database interactions
Branch: master
Clone or download
flimzy Merge pull request #55 from go-kivik/config
Add support for mocking config calls
Latest commit f0f6126 Jun 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gen Fix lint errors Jun 17, 2019
travis Use new linter Jun 17, 2019
.gitignore Generate a bunch more code Feb 12, 2019
.golangci.toml Use new linter Jun 17, 2019
.travis.yml Use Gopherjs 1.12 for tests May 20, 2019
Gopkg.toml Depend on latest flimzy/diff and flimzy/testy libraries Feb 11, 2019
LICENSE.md Initial commit Feb 7, 2019
README.md Rename ToDocument* to simply Document* Mar 11, 2019
bulk.go Add Final() methods, for using iterators within WillExecute() methods Mar 11, 2019
changes.go Add ETag support to mocked Changes Jun 9, 2019
client.go Add support for mocking config calls Jun 17, 2019
client_gen.go Add support for mocking config calls Jun 17, 2019
client_test.go Add support for mocking config calls Jun 17, 2019
clientexpectations_gen.go Add support for mocking config calls Jun 17, 2019
clientmock.go Updates for new CreateDB() function signature Mar 12, 2019
clientmock_gen.go Add support for mocking config calls Jun 17, 2019
codecov.yml
common.go Rename MockDB to DB Mar 11, 2019
context_test.go Add delay support Feb 9, 2019
db.go Rename MockDB to DB Mar 11, 2019
db_gen.go Rename MockDB to DB Mar 11, 2019
db_test.go Fix lint errors Jun 17, 2019
dbexpectations.go Generalize nameString to fieldString, and DRY Jun 17, 2019
dbexpectations_gen.go Rename DB() to dbo() so it doesn't appear in godoc Mar 11, 2019
dbmock.go Rename MockDB to DB Mar 11, 2019
dbmock_gen.go Rename MockDB to DB Mar 11, 2019
driver.go Rename MockClient to Client Mar 11, 2019
driver_test.go Basic infrastructure, and ExpectedClose() method Feb 7, 2019
expectations.go Generalize nameString to fieldString, and DRY Jun 17, 2019
helpers.go Rename ToDocument* to simply Document* Mar 11, 2019
helpers_test.go Rename ToDocument* to simply Document* Mar 11, 2019
iter.go Use common iter everywhere Feb 15, 2019
kivikmock.go Update godoc Feb 15, 2019
meets.go Rename MockDB to DB Mar 11, 2019
meets_test.go Rename MockDB to DB Mar 11, 2019
method_test.go Auto-generate method() method Feb 13, 2019
rows.go Add Final() methods, for using iterators within WillExecute() methods Mar 11, 2019
stringer_test.go Add support for mocking config calls Jun 17, 2019
updates.go Add Final() methods, for using iterators within WillExecute() methods Mar 11, 2019
util.go Generalize nameString to fieldString, and DRY Jun 17, 2019

README.md

Build Status Codecov Go Report Card GoDoc Website

Kivikmock

Package kivikmock is a mock library implementing a Kivik driver.

This package is heavily influenced by github.com/DATA-DOG/go-sqlmock, the SQL mock driver from Datadog.

Usage

To use this package, in your *_test.go file, create a mock Kivik connection:

client, mock, err := kivikmock.New()
if err != nil {
    panic(err)
}

The returned client object is a *kivik.Client, and can be passed to your methods to be tested. mock is used to control the execution of the mock driver, by setting expectations. To test a function which fetches a user, for example, you might do something like this:

func TestGetUser(t *testing.T) {
    client, mock, err := kivikmock.New()
    if err != nil {
        t.Fatal(err)
    }

    mock.ExpectDB().WithName("_users").WillReturn(mock.NewDB().
        ExpectGet().WithDocID("bob").
            WillReturn(kivikmock.DocumentT(t, `{"_id":"org.couchdb.user:bob"}`)),
    )
    user, err := GetUser(client, "bob")
    if err != nil {
        t.Error(err)
    }
    // other validation
}

Versions

This package targets the unstable release of Kivik.

License

This software is released under the terms of the Apache 2.0 license. See LICENCE.md, or read the full license.

You can’t perform that action at this time.