-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestqueryopts_test.go
115 lines (93 loc) · 3.85 KB
/
requestqueryopts_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
108
109
110
111
112
113
114
115
package gossamer
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestQueryOptions(t *testing.T) {
var opts QueryOptions
var err error
opts, err = CreateQueryOptions("$expand=Datastreams")
assert.Nil(t, err)
assert.True(t, opts.ExpandSet())
assert.Equal(t, 1, len(opts.GetExpandOption().GetValue()))
assert.Equal(t, "Datastreams", opts.GetExpandOption().GetValue()[0])
opts, err = CreateQueryOptions("$expand=Observations,ObservedProperty")
assert.Nil(t, err)
assert.True(t, opts.ExpandSet())
assert.Equal(t, 2, len(opts.GetExpandOption().GetValue()))
assert.Equal(t, "Observations", opts.GetExpandOption().GetValue()[0])
assert.Equal(t, "ObservedProperty", opts.GetExpandOption().GetValue()[1])
opts, err = CreateQueryOptions("$expand=Observations($select=result)")
assert.Nil(t, err)
assert.True(t, opts.ExpandSet())
assert.Equal(t, 1, len(opts.GetExpandOption().GetValue()))
assert.Equal(t, opts.GetExpandOption().GetValue()[0], "Observations($select=result)")
opts, err = CreateQueryOptions("$select=id,Observations&$expand=Observations/FeatureOfInterest")
assert.Nil(t, err)
assert.True(t, opts.SelectSet())
assert.Equal(t, 2, len(opts.GetSelectOption().GetValue()))
assert.Equal(t, opts.GetSelectOption().GetValue()[0], "id")
assert.Equal(t, opts.GetSelectOption().GetValue()[1], "Observations")
assert.True(t, opts.ExpandSet())
assert.Equal(t, 1, len(opts.GetExpandOption().GetValue()))
assert.Equal(t, opts.GetExpandOption().GetValue()[0], "Observations/FeatureOfInterest")
opts, err = CreateQueryOptions("$top=5")
assert.Nil(t, err)
assert.True(t, opts.TopSet())
assert.Equal(t, opts.GetTopOption().GetValue(), 5)
opts, err = CreateQueryOptions("$skip=5")
assert.Nil(t, err)
assert.True(t, opts.SkipSet())
assert.Equal(t, opts.GetSkipOption().GetValue(), 5)
opts, err = CreateQueryOptions("$expand=Datastream&$orderby=Datastreams/id desc, phenomenonTime")
assert.Nil(t, err)
assert.True(t, opts.ExpandSet())
assert.True(t, opts.OrderBySet())
opts, err = CreateQueryOptions("$expand=Datastreams/Observations/FeatureOfInterest&$filter=Datastreams/Observations/FeatureOfInterest/id eq 'FOI_1' and Datastreams/Observations/resultTime ge 2010-06-01T00:00:00Z and Datastreams/Observations/resultTime le 2010-07-01T00:00:00Z")
assert.Nil(t, err)
assert.True(t, opts.ExpandSet())
assert.Equal(t, 1, len(opts.GetExpandOption().GetValue()))
assert.Equal(t, "Datastreams/Observations/FeatureOfInterest", opts.GetExpandOption().GetValue()[0])
assert.True(t, opts.FilterSet())
/*
$filter=
Datastreams/Observations/FeatureOfInterest/id eq 'FOI_1'
and
Datastreams/Observations/resultTime ge 2010-06-01T00:00:00Z
and
Datastreams/Observations/resultTime le 2010-07-01T00:00:00Z
- Target
- Operation
- OpValue
- Operand
-
*/
opts, err = CreateQueryOptions("$count=true")
assert.Nil(t, err)
assert.True(t, opts.CountSet())
assert.True(t, opts.GetCountOption().GetValue())
opts, err = CreateQueryOptions("$filter=geo.distance(Locations/location,geography'POINT(-122, 43)') gt 1")
assert.Nil(t, err)
assert.True(t, opts.FilterSet())
opts, err = CreateQueryOptions("$select=result,resultTime")
assert.Nil(t, err)
assert.True(t, opts.SelectSet())
opts, err = CreateQueryOptions("$orderby=result")
assert.Nil(t, err)
assert.True(t, opts.OrderBySet())
opts, err = CreateQueryOptions("$top=5&$orderby=phenomenonTime desc")
assert.Nil(t, err)
assert.True(t, opts.TopSet())
assert.True(t, opts.OrderBySet())
opts, err = CreateQueryOptions("$skip=2&$top=2&$orderby=resultTime")
assert.Nil(t, err)
assert.True(t, opts.SkipSet())
assert.True(t, opts.TopSet())
assert.True(t, opts.OrderBySet())
opts, err = CreateQueryOptions("$filter=result lt 10.00")
assert.Nil(t, err)
assert.True(t, opts.FilterSet())
opts, err = CreateQueryOptions("$filter=Datastream/id eq '1'")
assert.Nil(t, err)
assert.True(t, opts.FilterSet())
}