github.com/influxdata/influxdb/v2@v2.7.6/mock/document_service.go (about) 1 package mock 2 3 import ( 4 "context" 5 6 "github.com/influxdata/influxdb/v2" 7 "github.com/influxdata/influxdb/v2/kit/platform" 8 ) 9 10 var _ influxdb.DocumentStore = &DocumentStore{} 11 12 // DocumentService is mocked document service. 13 type DocumentService struct { 14 CreateDocumentStoreFn func(ctx context.Context, name string) (influxdb.DocumentStore, error) 15 FindDocumentStoreFn func(ctx context.Context, name string) (influxdb.DocumentStore, error) 16 } 17 18 // CreateDocumentStore calls the mocked CreateDocumentStoreFn. 19 func (s *DocumentService) CreateDocumentStore(ctx context.Context, name string) (influxdb.DocumentStore, error) { 20 return s.CreateDocumentStoreFn(ctx, name) 21 } 22 23 // FindDocumentStore calls the mocked FindDocumentStoreFn. 24 func (s *DocumentService) FindDocumentStore(ctx context.Context, name string) (influxdb.DocumentStore, error) { 25 return s.FindDocumentStoreFn(ctx, name) 26 } 27 28 // NewDocumentService returns a mock of DocumentService where its methods will return zero values. 29 func NewDocumentService() *DocumentService { 30 return &DocumentService{ 31 CreateDocumentStoreFn: func(ctx context.Context, name string) (influxdb.DocumentStore, error) { 32 return nil, nil 33 }, 34 FindDocumentStoreFn: func(ctx context.Context, name string) (influxdb.DocumentStore, error) { 35 return nil, nil 36 }, 37 } 38 } 39 40 // DocumentStore is the mocked document store. 41 type DocumentStore struct { 42 TimeGenerator TimeGenerator 43 CreateDocumentFn func(ctx context.Context, d *influxdb.Document) error 44 FindDocumentFn func(ctx context.Context, id platform.ID) (*influxdb.Document, error) 45 FindDocumentsFn func(ctx context.Context, oid platform.ID) ([]*influxdb.Document, error) 46 } 47 48 // NewDocumentStore returns a mock of DocumentStore where its methods will return zero values. 49 func NewDocumentStore() *DocumentStore { 50 return &DocumentStore{ 51 CreateDocumentFn: func(ctx context.Context, d *influxdb.Document) error { 52 return nil 53 }, 54 FindDocumentFn: func(ctx context.Context, id platform.ID) (document *influxdb.Document, e error) { 55 return nil, nil 56 }, 57 FindDocumentsFn: func(ctx context.Context, oid platform.ID) ([]*influxdb.Document, error) { 58 return nil, nil 59 }, 60 } 61 } 62 63 // CreateDocument will call the mocked CreateDocumentFn. 64 func (s *DocumentStore) CreateDocument(ctx context.Context, d *influxdb.Document) error { 65 return s.CreateDocumentFn(ctx, d) 66 } 67 68 // FindDocument will call the mocked FindDocumentFn. 69 func (s *DocumentStore) FindDocument(ctx context.Context, id platform.ID) (*influxdb.Document, error) { 70 return s.FindDocumentFn(ctx, id) 71 } 72 73 // FindDocuments will call the mocked FindDocumentsFn. 74 func (s *DocumentStore) FindDocuments(ctx context.Context, oid platform.ID) ([]*influxdb.Document, error) { 75 return s.FindDocumentsFn(ctx, oid) 76 }