-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollections_test.go
More file actions
61 lines (56 loc) · 2.1 KB
/
Copy pathcollections_test.go
File metadata and controls
61 lines (56 loc) · 2.1 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
package main
import "testing"
// crsCode extracts an EPSG code from the crs field of a Collection body in any
// of its accepted forms, defaulting to 4326.
func TestCrsCode(t *testing.T) {
cases := map[string]int{
`["http://www.opengis.net/def/crs/EPSG/0/25832"]`: 25832,
`"urn:ogc:def:crs:EPSG::3812"`: 3812,
`4326`: 4326,
`"4258"`: 4258,
`null`: 4326, // absent -> default CRS84
`"not a crs"`: 4326,
}
for in, want := range cases {
if got := crsCode([]byte(in)); got != want {
t.Errorf("crsCode(%s) = %d, want %d", in, got, want)
}
}
}
// validID guards the collection id interpolated into CREATE/DROP TABLE.
func TestValidID(t *testing.T) {
good := []string{"ships", "drones", "fleet_2026", "_tmp", "a"}
bad := []string{"", "Ships", "bad-name", "drop table", "f leet", "2026fleet", "x;y", `a"b`}
for _, s := range good {
if !validID.MatchString(s) {
t.Errorf("validID rejected a valid id %q", s)
}
}
for _, s := range bad {
if validID.MatchString(s) {
t.Errorf("validID accepted an unsafe id %q", s)
}
}
}
// propSel / featCols switch the projection between the generic JSONB properties
// column and the typed ships columns (the envelope is assembled in the tier).
func TestSchemaMode(t *testing.T) {
if propSel(true) != "CAST(coalesce(properties,CAST('{}' AS jsonb)) AS text)" {
t.Errorf("generic propSel wrong: %s", propSel(true))
}
if propSel(false) != "mmsi, name" {
t.Errorf("typed propSel wrong: %s", propSel(false))
}
if featCols(true) != "id, properties" || featCols(false) != "id, mmsi, name" {
t.Errorf("featCols wrong: %q / %q", featCols(true), featCols(false))
}
}
// propsJSON serialises a feature's properties for the generic jsonb column.
func TestPropsJSON(t *testing.T) {
if got := propsJSON(nil); got != "{}" {
t.Errorf("propsJSON(nil) = %q, want {}", got)
}
if got := propsJSON(map[string]any{"model": "X500"}); got != `{"model":"X500"}` {
t.Errorf("propsJSON = %q", got)
}
}