forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_service.go
102 lines (87 loc) · 3.77 KB
/
document_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package mock
import (
"context"
"github.com/influxdata/influxdb/v2"
)
var _ influxdb.DocumentStore = &DocumentStore{}
// DocumentService is mocked document service.
type DocumentService struct {
CreateDocumentStoreFn func(ctx context.Context, name string) (influxdb.DocumentStore, error)
FindDocumentStoreFn func(ctx context.Context, name string) (influxdb.DocumentStore, error)
}
// CreateDocumentStore calls the mocked CreateDocumentStoreFn.
func (s *DocumentService) CreateDocumentStore(ctx context.Context, name string) (influxdb.DocumentStore, error) {
return s.CreateDocumentStoreFn(ctx, name)
}
// FindDocumentStore calls the mocked FindDocumentStoreFn.
func (s *DocumentService) FindDocumentStore(ctx context.Context, name string) (influxdb.DocumentStore, error) {
return s.FindDocumentStoreFn(ctx, name)
}
// NewDocumentService returns a mock of DocumentService where its methods will return zero values.
func NewDocumentService() *DocumentService {
return &DocumentService{
CreateDocumentStoreFn: func(ctx context.Context, name string) (influxdb.DocumentStore, error) {
return nil, nil
},
FindDocumentStoreFn: func(ctx context.Context, name string) (influxdb.DocumentStore, error) {
return nil, nil
},
}
}
// DocumentStore is the mocked document store.
type DocumentStore struct {
TimeGenerator TimeGenerator
CreateDocumentFn func(ctx context.Context, d *influxdb.Document) error
FindDocumentFn func(ctx context.Context, id influxdb.ID) (*influxdb.Document, error)
UpdateDocumentFn func(ctx context.Context, d *influxdb.Document) error
DeleteDocumentFn func(ctx context.Context, id influxdb.ID) error
FindDocumentsFn func(ctx context.Context, opts ...influxdb.DocumentFindOptions) ([]*influxdb.Document, error)
DeleteDocumentsFn func(ctx context.Context, opts ...influxdb.DocumentFindOptions) error
}
// NewDocumentStore returns a mock of DocumentStore where its methods will return zero values.
func NewDocumentStore() *DocumentStore {
return &DocumentStore{
CreateDocumentFn: func(ctx context.Context, d *influxdb.Document) error {
return nil
},
FindDocumentFn: func(ctx context.Context, id influxdb.ID) (document *influxdb.Document, e error) {
return nil, nil
},
UpdateDocumentFn: func(ctx context.Context, d *influxdb.Document) error {
return nil
},
DeleteDocumentFn: func(ctx context.Context, id influxdb.ID) error {
return nil
},
FindDocumentsFn: func(ctx context.Context, opts ...influxdb.DocumentFindOptions) ([]*influxdb.Document, error) {
return nil, nil
},
DeleteDocumentsFn: func(ctx context.Context, opts ...influxdb.DocumentFindOptions) error {
return nil
},
}
}
// CreateDocument will call the mocked CreateDocumentFn.
func (s *DocumentStore) CreateDocument(ctx context.Context, d *influxdb.Document) error {
return s.CreateDocumentFn(ctx, d)
}
// FindDocument will call the mocked FindDocumentFn.
func (s *DocumentStore) FindDocument(ctx context.Context, id influxdb.ID) (*influxdb.Document, error) {
return s.FindDocumentFn(ctx, id)
}
// UpdateDocument will call the mocked UpdateDocumentFn.
func (s *DocumentStore) UpdateDocument(ctx context.Context, d *influxdb.Document) error {
return s.UpdateDocumentFn(ctx, d)
}
// DeleteDocument will call the mocked DeleteDocumentFn.
func (s *DocumentStore) DeleteDocument(ctx context.Context, id influxdb.ID) error {
return s.DeleteDocumentFn(ctx, id)
}
// FindDocuments will call the mocked FindDocumentsFn.
func (s *DocumentStore) FindDocuments(ctx context.Context, opts ...influxdb.DocumentFindOptions) ([]*influxdb.Document, error) {
return s.FindDocumentsFn(ctx, opts...)
}
// DeleteDocuments will call the mocked DeleteDocumentsFn.
func (s *DocumentStore) DeleteDocuments(ctx context.Context, opts ...influxdb.DocumentFindOptions) error {
return s.DeleteDocumentsFn(ctx, opts...)
}