-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream_conformance_test.go
More file actions
95 lines (89 loc) · 3 KB
/
Copy pathstream_conformance_test.go
File metadata and controls
95 lines (89 loc) · 3 KB
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
package main
import (
"encoding/json"
"net/http/httptest"
"strings"
"testing"
)
// The service declares the OGC MF Part 4 (Continuous Query) conformance class.
func TestConformanceDeclaresPart4(t *testing.T) {
rec := httptest.NewRecorder()
conformance(rec, httptest.NewRequest("GET", "/conformance", nil))
var body struct {
ConformsTo []string `json:"conformsTo"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
const want = "http://www.opengis.net/spec/ogcapi-movingfeatures-4/1.0/conf/cquery"
for _, c := range body.ConformsTo {
if c == want {
return
}
}
t.Errorf("conformance does not declare the MF Part 4 cquery class %q", want)
}
// The API definition documents the continuous-query paths.
func TestAPIDeclaresStreamingPaths(t *testing.T) {
rec := httptest.NewRecorder()
apiDoc(rec, httptest.NewRequest("GET", "/api", nil))
var doc struct {
Paths map[string]any `json:"paths"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &doc); err != nil {
t.Fatal(err)
}
for _, p := range []string{
"/collections/{cid}/items/{fid}/tproperties/{pname}/queries",
"/collections/{cid}/items/{fid}/tproperties/{pname}/ingest",
"/collections/{cid}/items/{fid}/tgsequence/queries",
} {
if _, ok := doc.Paths[p]; !ok {
t.Errorf("API definition is missing the streaming path %q", p)
}
}
}
// The cquery link object carries the properties Requirement 1 mandates.
func TestCqueryLinkShape(t *testing.T) {
cq := &contQuery{id: "q1", spec: QuerySpec{CID: "ships", FID: 7, Pname: "speed", Op: "mul"}}
link := cqueryLink(httptest.NewRequest("GET", "http://host/x", nil), cq)
for _, k := range []string{"rel", "queryId", "href", "channel", "status", "type"} {
if _, ok := link[k]; !ok {
t.Errorf("cquery link object missing required property %q", k)
}
}
if link["rel"] != "cquery" {
t.Errorf("rel = %v, want cquery", link["rel"])
}
if link["queryId"] != "q1" {
t.Errorf("queryId = %v, want q1", link["queryId"])
}
if link["status"] != "running" {
t.Errorf("status = %v, want running", link["status"])
}
}
// A geometry query's cquery link is scoped to the tgsequence resource.
func TestCqueryLinkGeometryScope(t *testing.T) {
cq := &contQuery{id: "q2", spec: QuerySpec{Kind: "geometry", CID: "ships", FID: 7}}
link := cqueryLink(httptest.NewRequest("GET", "http://host/x", nil), cq)
ch, _ := link["channel"].(string)
if !strings.HasPrefix(ch, "/collections/ships/items/7/tgsequence/queries") {
t.Errorf("geometry channel = %q, want a tgsequence/queries path", ch)
}
}
// The window-aggregation result carries the bounds Requirement 2 mandates.
func TestWindowResultShape(t *testing.T) {
ev := Event{
"windowStart": "2026-01-01T00:00:00Z",
"windowEnd": "2026-01-01T00:00:30Z",
"aggregation": "AVG",
"property": "speed",
"value": 6.2,
"count": 3,
}
for _, k := range []string{"windowStart", "windowEnd", "aggregation", "value", "count"} {
if _, ok := ev[k]; !ok {
t.Errorf("window aggregate result missing required field %q", k)
}
}
}