# README
MockDB
Package mockdb 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 := mockdb.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 := mockdb.New()
if err != nil {
t.Fatal(err)
}
mock.ExpectDB().WithName("_users").WillReturn(mock.NewDB().
ExpectGet().WithDocID("bob").
WillReturn(mockdb.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.
# Packages
Package main generates the bulk of the mockdb driver.
# Functions
Document converts i, which should be of a supported type (see below), into a document which can be passed to ExpectedGet.WillReturn().
DocumentT calls Document, and passes any error to t.Fatal.
New creates a kivik client connection and a mock to manage expectations.
NewChanges returns a new, empty changes set, which can be returned by the DB.Changes() expectation.
NewDBUpdates returns a new, empty update set, which can be returned by the DBUpdates() expectation.
NewRows returns a new, empty set of rows, which can be returned by any of the row-returning expectations.
NewT works exactly as New, except that any error will be passed to t.Fatal.
# Structs
Changes is a mocked collection of Changes results.
Client allows configuring the mock kivik client.
DB serves to create expectations for database actions to mock and test real database behavior.
ExpectedAllDBs represents an expectation for a call to AllDBs().
ExpectedAllDBsStats represents an expectation for a call to AllDBsStats().
ExpectedAllDocs represents an expectation for a call to DB.AllDocs().
ExpectedBulkDocs represents an expectation for a call to DB.BulkDocs().
ExpectedBulkGet represents an expectation for a call to DB.BulkGet().
ExpectedChanges represents an expectation for a call to DB.Changes().
ExpectedClose represents an expectation for a call to Close().
ExpectedClusterSetup represents an expectation for a call to ClusterSetup().
ExpectedClusterStatus represents an expectation for a call to ClusterStatus().
ExpectedCompact represents an expectation for a call to DB.Compact().
ExpectedCompactView represents an expectation for a call to DB.CompactView().
ExpectedConfig represents an expectation for a call to Config().
ExpectedConfigSection represents an expectation for a call to ConfigSection().
ExpectedConfigValue represents an expectation for a call to ConfigValue().
ExpectedCopy represents an expectation for a call to DB.Copy().
ExpectedCreateDB represents an expectation to call the CreateDB() method.
ExpectedCreateDoc represents an expectation for a call to DB.CreateDoc().
ExpectedCreateIndex represents an expectation for a call to DB.CreateIndex().
ExpectedDB represents an expectation for a call to DB().
ExpectedDBClose is used to manage *kivik.Client.Close expectation returned by Mock.ExpectClose.
ExpectedDBExists represents an expectation for a call to DBExists().
ExpectedDBsStats represents an expectation for a call to DBsStats().
ExpectedDBUpdates represents an expectation for a call to DBUpdates().
ExpectedDelete represents an expectation for a call to DB.Delete().
ExpectedDeleteAttachment represents an expectation for a call to DB.DeleteAttachment().
ExpectedDeleteConfigKey represents an expectation for a call to DeleteConfigKey().
ExpectedDeleteIndex represents an expectation for a call to DB.DeleteIndex().
ExpectedDesignDocs represents an expectation for a call to DB.DesignDocs().
ExpectedDestroyDB represents an expectation for a call to DestroyDB().
ExpectedExplain represents an expectation for a call to DB.Explain().
ExpectedFind represents an expectation for a call to DB.Find().
ExpectedFlush represents an expectation for a call to DB.Flush().
ExpectedGet represents an expectation for a call to DB.Get().
ExpectedGetAttachment represents an expectation for a call to DB.GetAttachment().
ExpectedGetAttachmentMeta represents an expectation for a call to DB.GetAttachmentMeta().
ExpectedGetIndexes represents an expectation for a call to DB.GetIndexes().
ExpectedGetReplications represents an expectation for a call to GetReplications().
ExpectedGetRev represents an expectation for a call to DB.GetRev().
ExpectedLocalDocs represents an expectation for a call to DB.LocalDocs().
ExpectedMembership represents an expectation for a call to Membership().
ExpectedOpenRevs represents an expectation for a call to DB.OpenRevs().
ExpectedPartitionStats represents an expectation for a call to DB.PartitionStats().
ExpectedPing represents an expectation for a call to Ping().
ExpectedPurge represents an expectation for a call to DB.Purge().
ExpectedPut represents an expectation for a call to DB.Put().
ExpectedPutAttachment represents an expectation for a call to DB.PutAttachment().
ExpectedQuery represents an expectation for a call to DB.Query().
ExpectedReplicate represents an expectation for a call to Replicate().
ExpectedRevsDiff represents an expectation for a call to DB.RevsDiff().
ExpectedSecurity represents an expectation for a call to DB.Security().
ExpectedSession represents an expectation for a call to Session().
ExpectedSetConfigValue represents an expectation for a call to SetConfigValue().
ExpectedSetSecurity represents an expectation for a call to DB.SetSecurity().
ExpectedStats represents an expectation for a call to DB.Stats().
ExpectedVersion represents an expectation for a call to Version().
ExpectedViewCleanup represents an expectation for a call to DB.ViewCleanup().
Replication is a replication instance.
Rows is a mocked collection of rows.
Updates is a mocked collection of database updates.