1package mock
2
3import (
4	"context"
5
6	"github.com/go-kivik/kivik/driver"
7)
8
9// DB mocks a driver.DB
10type DB struct {
11	// ID is a unique identifier for the DB instance.
12	ID                   string
13	AllDocsFunc          func(ctx context.Context, options map[string]interface{}) (driver.Rows, error)
14	GetFunc              func(ctx context.Context, docID string, options map[string]interface{}) (*driver.Document, error)
15	CreateDocFunc        func(ctx context.Context, doc interface{}, options map[string]interface{}) (docID, rev string, err error)
16	PutFunc              func(ctx context.Context, docID string, doc interface{}, options map[string]interface{}) (rev string, err error)
17	DeleteFunc           func(ctx context.Context, docID, rev string, options map[string]interface{}) (newRev string, err error)
18	StatsFunc            func(ctx context.Context) (*driver.DBStats, error)
19	CompactFunc          func(ctx context.Context) error
20	CompactViewFunc      func(ctx context.Context, ddocID string) error
21	ViewCleanupFunc      func(ctx context.Context) error
22	SecurityFunc         func(ctx context.Context) (*driver.Security, error)
23	SetSecurityFunc      func(ctx context.Context, security *driver.Security) error
24	ChangesFunc          func(ctx context.Context, options map[string]interface{}) (driver.Changes, error)
25	PutAttachmentFunc    func(ctx context.Context, docID, rev string, att *driver.Attachment, options map[string]interface{}) (newRev string, err error)
26	GetAttachmentFunc    func(ctx context.Context, docID, rev, filename string, options map[string]interface{}) (*driver.Attachment, error)
27	DeleteAttachmentFunc func(ctx context.Context, docID, rev, filename string, options map[string]interface{}) (newRev string, err error)
28	QueryFunc            func(context.Context, string, string, map[string]interface{}) (driver.Rows, error)
29}
30
31var _ driver.DB = &DB{}
32
33// AllDocs calls db.AllDocsFunc
34func (db *DB) AllDocs(ctx context.Context, options map[string]interface{}) (driver.Rows, error) {
35	return db.AllDocsFunc(ctx, options)
36}
37
38// Get calls db.GetFunc
39func (db *DB) Get(ctx context.Context, docID string, opts map[string]interface{}) (*driver.Document, error) {
40	return db.GetFunc(ctx, docID, opts)
41}
42
43// CreateDoc calls db.CreateDocFunc
44func (db *DB) CreateDoc(ctx context.Context, doc interface{}, opts map[string]interface{}) (string, string, error) {
45	return db.CreateDocFunc(ctx, doc, opts)
46}
47
48// Put calls db.PutFunc
49func (db *DB) Put(ctx context.Context, docID string, doc interface{}, opts map[string]interface{}) (string, error) {
50	return db.PutFunc(ctx, docID, doc, opts)
51}
52
53// Delete calls db.DeleteFunc
54func (db *DB) Delete(ctx context.Context, docID, rev string, opts map[string]interface{}) (string, error) {
55	return db.DeleteFunc(ctx, docID, rev, opts)
56}
57
58// Stats calls db.StatsFunc
59func (db *DB) Stats(ctx context.Context) (*driver.DBStats, error) {
60	return db.StatsFunc(ctx)
61}
62
63// Compact calls db.CompactFunc
64func (db *DB) Compact(ctx context.Context) error {
65	return db.CompactFunc(ctx)
66}
67
68// CompactView calls db.CompactViewFunc
69func (db *DB) CompactView(ctx context.Context, docID string) error {
70	return db.CompactViewFunc(ctx, docID)
71}
72
73// ViewCleanup calls db.ViewCleanupFunc
74func (db *DB) ViewCleanup(ctx context.Context) error {
75	return db.ViewCleanupFunc(ctx)
76}
77
78// Security calls db.SecurityFunc
79func (db *DB) Security(ctx context.Context) (*driver.Security, error) {
80	return db.SecurityFunc(ctx)
81}
82
83// SetSecurity calls db.SetSecurityFunc
84func (db *DB) SetSecurity(ctx context.Context, security *driver.Security) error {
85	return db.SetSecurityFunc(ctx, security)
86}
87
88// Changes calls db.ChangesFunc
89func (db *DB) Changes(ctx context.Context, opts map[string]interface{}) (driver.Changes, error) {
90	return db.ChangesFunc(ctx, opts)
91}
92
93// PutAttachment calls db.PutAttachmentFunc
94func (db *DB) PutAttachment(ctx context.Context, docID, rev string, att *driver.Attachment, opts map[string]interface{}) (string, error) {
95	return db.PutAttachmentFunc(ctx, docID, rev, att, opts)
96}
97
98// GetAttachment calls db.GetAttachmentFunc
99func (db *DB) GetAttachment(ctx context.Context, docID, rev, filename string, opts map[string]interface{}) (*driver.Attachment, error) {
100	return db.GetAttachmentFunc(ctx, docID, rev, filename, opts)
101}
102
103// DeleteAttachment calls db.DeleteAttachmentFunc
104func (db *DB) DeleteAttachment(ctx context.Context, docID, rev, filename string, opts map[string]interface{}) (string, error) {
105	return db.DeleteAttachmentFunc(ctx, docID, rev, filename, opts)
106}
107
108// Query calls db.QueryFunc
109func (db *DB) Query(ctx context.Context, ddoc, view string, opts map[string]interface{}) (driver.Rows, error) {
110	return db.QueryFunc(ctx, ddoc, view, opts)
111}
112
113// Finder mocks a driver.DB and driver.Finder
114type Finder struct {
115	*DB
116	CreateIndexFunc func(context.Context, string, string, interface{}) error
117	DeleteIndexFunc func(context.Context, string, string) error
118	FindFunc        func(context.Context, interface{}) (driver.Rows, error)
119	GetIndexesFunc  func(context.Context) ([]driver.Index, error)
120	ExplainFunc     func(context.Context, interface{}) (*driver.QueryPlan, error)
121}
122
123var _ driver.Finder = &Finder{}
124
125// CreateIndex calls db.CreateIndexFunc
126func (db *Finder) CreateIndex(ctx context.Context, ddoc, name string, index interface{}) error {
127	return db.CreateIndexFunc(ctx, ddoc, name, index)
128}
129
130// DeleteIndex calls db.DeleteIndexFunc
131func (db *Finder) DeleteIndex(ctx context.Context, ddoc, name string) error {
132	return db.DeleteIndexFunc(ctx, ddoc, name)
133}
134
135// Find calls db.FindFunc
136func (db *Finder) Find(ctx context.Context, query interface{}) (driver.Rows, error) {
137	return db.FindFunc(ctx, query)
138}
139
140// GetIndexes calls db.GetIndexesFunc
141func (db *Finder) GetIndexes(ctx context.Context) ([]driver.Index, error) {
142	return db.GetIndexesFunc(ctx)
143}
144
145// Explain calls db.ExplainFunc
146func (db *Finder) Explain(ctx context.Context, query interface{}) (*driver.QueryPlan, error) {
147	return db.ExplainFunc(ctx, query)
148}
149
150// Flusher mocks a driver.DB and driver.Flusher
151type Flusher struct {
152	*DB
153	FlushFunc func(context.Context) error
154}
155
156var _ driver.Flusher = &Flusher{}
157
158// Flush calls db.FlushFunc
159func (db *Flusher) Flush(ctx context.Context) error {
160	return db.FlushFunc(ctx)
161}
162
163// MetaGetter mocks a driver.DB and driver.MetaGetter
164type MetaGetter struct {
165	*DB
166	GetMetaFunc func(context.Context, string, map[string]interface{}) (int64, string, error)
167}
168
169var _ driver.MetaGetter = &MetaGetter{}
170
171// GetMeta calls db.GetMetaFunc
172func (db *MetaGetter) GetMeta(ctx context.Context, docID string, opts map[string]interface{}) (int64, string, error) {
173	return db.GetMetaFunc(ctx, docID, opts)
174}
175
176// Copier mocks a driver.DB and driver.Copier.
177type Copier struct {
178	*DB
179	CopyFunc func(context.Context, string, string, map[string]interface{}) (string, error)
180}
181
182var _ driver.Copier = &Copier{}
183
184// Copy calls db.CopyFunc
185func (db *Copier) Copy(ctx context.Context, target, source string, options map[string]interface{}) (string, error) {
186	return db.CopyFunc(ctx, target, source, options)
187}
188
189// AttachmentMetaGetter mocks a driver.DB and driver.AttachmentMetaGetter
190type AttachmentMetaGetter struct {
191	*DB
192	GetAttachmentMetaFunc func(ctx context.Context, docID, rev, filename string, options map[string]interface{}) (*driver.Attachment, error)
193}
194
195var _ driver.AttachmentMetaGetter = &AttachmentMetaGetter{}
196
197// GetAttachmentMeta calls db.GetAttachmentMetaFunc
198func (db *AttachmentMetaGetter) GetAttachmentMeta(ctx context.Context, docID, rev, filename string, options map[string]interface{}) (*driver.Attachment, error) {
199	return db.GetAttachmentMetaFunc(ctx, docID, rev, filename, options)
200}
201