-
Notifications
You must be signed in to change notification settings - Fork 110
/
navigation_service.go
83 lines (70 loc) · 3.05 KB
/
navigation_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
package inject
import (
"context"
geo "github.com/kellydunn/golang-geo"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.viam.com/rdk/services/navigation"
)
// NavigationService represents a fake instance of a navigation service.
type NavigationService struct {
navigation.Service
ModeFunc func(ctx context.Context, extra map[string]interface{}) (navigation.Mode, error)
SetModeFunc func(ctx context.Context, mode navigation.Mode, extra map[string]interface{}) error
LocationFunc func(ctx context.Context, extra map[string]interface{}) (*geo.Point, error)
WaypointsFunc func(ctx context.Context, extra map[string]interface{}) ([]navigation.Waypoint, error)
AddWaypointFunc func(ctx context.Context, point *geo.Point, extra map[string]interface{}) error
RemoveWaypointFunc func(ctx context.Context, id primitive.ObjectID, extra map[string]interface{}) error
DoCommandFunc func(ctx context.Context,
cmd map[string]interface{}) (map[string]interface{}, error)
}
// Mode calls the injected ModeFunc or the real version.
func (ns *NavigationService) Mode(ctx context.Context, extra map[string]interface{}) (navigation.Mode, error) {
if ns.ModeFunc == nil {
return ns.Service.Mode(ctx, extra)
}
return ns.ModeFunc(ctx, extra)
}
// SetMode calls the injected SetModeFunc or the real version.
func (ns *NavigationService) SetMode(ctx context.Context, mode navigation.Mode, extra map[string]interface{}) error {
if ns.SetModeFunc == nil {
return ns.Service.SetMode(ctx, mode, extra)
}
return ns.SetModeFunc(ctx, mode, extra)
}
// Location calls the injected LocationFunc or the real version.
func (ns *NavigationService) Location(ctx context.Context, extra map[string]interface{}) (*geo.Point, error) {
if ns.LocationFunc == nil {
return ns.Service.Location(ctx, extra)
}
return ns.LocationFunc(ctx, extra)
}
// Waypoints calls the injected WaypointsFunc or the real version.
func (ns *NavigationService) Waypoints(ctx context.Context, extra map[string]interface{}) ([]navigation.Waypoint, error) {
if ns.WaypointsFunc == nil {
return ns.Service.Waypoints(ctx, extra)
}
return ns.WaypointsFunc(ctx, extra)
}
// AddWaypoint calls the injected AddWaypointFunc or the real version.
func (ns *NavigationService) AddWaypoint(ctx context.Context, point *geo.Point, extra map[string]interface{}) error {
if ns.AddWaypointFunc == nil {
return ns.Service.AddWaypoint(ctx, point, extra)
}
return ns.AddWaypointFunc(ctx, point, extra)
}
// RemoveWaypoint calls the injected RemoveWaypointFunc or the real version.
func (ns *NavigationService) RemoveWaypoint(ctx context.Context, id primitive.ObjectID, extra map[string]interface{}) error {
if ns.RemoveWaypointFunc == nil {
return ns.Service.RemoveWaypoint(ctx, id, extra)
}
return ns.RemoveWaypointFunc(ctx, id, extra)
}
// DoCommand calls the injected DoCommand or the real variant.
func (ns *NavigationService) DoCommand(ctx context.Context,
cmd map[string]interface{},
) (map[string]interface{}, error) {
if ns.DoCommandFunc == nil {
return ns.Service.DoCommand(ctx, cmd)
}
return ns.DoCommandFunc(ctx, cmd)
}