-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
107 lines (94 loc) · 3.12 KB
/
options_test.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
103
104
105
106
107
package gosrm
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOptionImpl_apply(t *testing.T) {
var u url.URL
f := optionImpl(func(u *url.URL) {
u.Path = "/test"
})
f.apply(&u)
assert.Equal(t, "/test", u.Path)
}
func TestSetQueryParam(t *testing.T) {
var u url.URL
setQueryParam(&u, "key", "value")
assert.Equal(t, "key=value", u.RawQuery)
assert.Equal(t, "value", u.Query().Get("key"))
}
func TestOptions(t *testing.T) {
var osrm OSRMClient
var u url.URL
opts := []Option{
WithNumber(3),
WithAlternatives(true),
WithSteps(false),
WithAnnotations(AnnotationsSpeed),
WithGeometries(GeometryGeoJSON),
WithOverview(OverviewSimplified),
WithContinueStraight(ContinueStraightTrue),
WithSources([]uint16{0, 1, 2}),
WithDestinations([]uint16{1}),
WithTimestamps([]int64{1234, 5721}),
WithGaps(GapsIgnore),
WithTidy(true),
WithWaypoints([]uint16{0, 1}),
WithRadiuses([]float32{1.567, 2.5683}),
WithRoundTrip(false),
WithSource(SourceAny),
WithDestination(DestinationLast),
WithBearings([]Bearing{{Value: 200, Range: 50}}),
WithGenerateHints(true),
WithHints([]string{"asd", "qwe"}),
WithApproaches([]Approaches{ApproachesUnrestricted}),
WithExclude([]string{"motorway"}),
WithSnapping(SnappingDefault),
WithCustomOption("opt", "val"),
WithSkipWaypoints(false),
WithFallbackSpeed(1.432123),
WithScaleFactor(1),
WithFallbackCoordinate(FallbackCoordinateInput),
}
osrm.applyOpts(&u, opts)
q := u.Query()
assert.Equal(t, "3", q.Get("number"))
assert.Equal(t, "true", q.Get("alternatives"))
assert.Equal(t, "false", q.Get("steps"))
assert.Equal(t, string(AnnotationsSpeed), q.Get("annotations"))
assert.Equal(t, string(GeometryGeoJSON), q.Get("geometries"))
assert.Equal(t, string(OverviewSimplified), q.Get("overview"))
assert.Equal(t, string(ContinueStraightTrue), q.Get("continue_straight"))
assert.Equal(t, "0;1;2", q.Get("sources"))
assert.Equal(t, "1", q.Get("destinations"))
assert.Equal(t, "1234;5721", q.Get("timestamps"))
assert.Equal(t, "ignore", q.Get("gaps"))
assert.Equal(t, "true", q.Get("tidy"))
assert.Equal(t, "0;1", q.Get("waypoints"))
assert.Equal(t, "1.567000;2.568300", q.Get("radiuses"))
assert.Equal(t, "false", q.Get("roundtrip"))
assert.Equal(t, "any", q.Get("source"))
assert.Equal(t, "last", q.Get("destination"))
assert.Equal(t, "200,50", q.Get("bearings"))
assert.Equal(t, "true", q.Get("generate_hints"))
assert.Equal(t, "asd;qwe", q.Get("hints"))
assert.Equal(t, "unrestricted", q.Get("approaches"))
assert.Equal(t, "motorway", q.Get("exclude"))
assert.Equal(t, "default", q.Get("snapping"))
assert.Equal(t, "val", q.Get("opt"))
assert.Equal(t, "false", q.Get("skip_waypoints"))
assert.Equal(t, "1.432123", q.Get("fallback_speed"))
assert.Equal(t, "1.000000", q.Get("scale_factor"))
assert.Equal(t, string(FallbackCoordinateInput), q.Get("fallback_coordinate"))
opts = []Option{
WithSources(nil),
WithDestinations(nil),
WithRadiuses(nil),
}
osrm.applyOpts(&u, opts)
q = u.Query()
assert.Equal(t, "all", q.Get("sources"))
assert.Equal(t, "all", q.Get("destinations"))
assert.Equal(t, "unlimited", q.Get("radiuses"))
}