forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_service.go
63 lines (52 loc) · 2.51 KB
/
source_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
package mock
import (
"context"
platform "github.com/influxdata/influxdb"
)
var _ platform.SourceService = (*SourceService)(nil)
// SourceService is a mock implementation of platform.SourceService.
type SourceService struct {
DefaultSourceFn func(context.Context) (*platform.Source, error)
FindSourceByIDFn func(context.Context, platform.ID) (*platform.Source, error)
FindSourcesFn func(context.Context, platform.FindOptions) ([]*platform.Source, int, error)
CreateSourceFn func(context.Context, *platform.Source) error
UpdateSourceFn func(context.Context, platform.ID, platform.SourceUpdate) (*platform.Source, error)
DeleteSourceFn func(context.Context, platform.ID) error
}
// NewSourceService returns a mock of SourceService where its methods will return zero values.
func NewSourceService() *SourceService {
return &SourceService{
DefaultSourceFn: func(context.Context) (*platform.Source, error) { return nil, nil },
FindSourceByIDFn: func(context.Context, platform.ID) (*platform.Source, error) { return nil, nil },
CreateSourceFn: func(context.Context, *platform.Source) error { return nil },
UpdateSourceFn: func(context.Context, platform.ID, platform.SourceUpdate) (*platform.Source, error) { return nil, nil },
DeleteSourceFn: func(context.Context, platform.ID) error { return nil },
FindSourcesFn: func(context.Context, platform.FindOptions) ([]*platform.Source, int, error) {
return nil, 0, nil
},
}
}
// DefaultSource retrieves the default source.
func (s *SourceService) DefaultSource(ctx context.Context) (*platform.Source, error) {
return s.DefaultSourceFn(ctx)
}
// FindSourceByID retrieves a source by its ID.
func (s *SourceService) FindSourceByID(ctx context.Context, id platform.ID) (*platform.Source, error) {
return s.FindSourceByIDFn(ctx, id)
}
// FindSources returns a list of all sources.
func (s *SourceService) FindSources(ctx context.Context, opts platform.FindOptions) ([]*platform.Source, int, error) {
return s.FindSourcesFn(ctx, opts)
}
// CreateSource sets the sources ID and stores it.
func (s *SourceService) CreateSource(ctx context.Context, source *platform.Source) error {
return s.CreateSourceFn(ctx, source)
}
// DeleteSource removes the source.
func (s *SourceService) DeleteSource(ctx context.Context, id platform.ID) error {
return s.DeleteSourceFn(ctx, id)
}
// UpdateSource updates the source.
func (s *SourceService) UpdateSource(ctx context.Context, id platform.ID, upd platform.SourceUpdate) (*platform.Source, error) {
return s.UpdateSourceFn(ctx, id, upd)
}