-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmvt_test.go
68 lines (55 loc) · 2.12 KB
/
mvt_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
package xonacatl
import (
"bytes"
"testing"
)
func runCopyMVT(input []byte, layers map[string]bool) (output []byte, err error) {
var buf bytes.Buffer
rd := bytes.NewBuffer(input)
copier := NewCopyMVTLayers(layers)
err = copier.CopyLayers(rd, &buf)
if err == nil {
output = buf.Bytes()
}
return
}
func runCopyMVTSuccess(input []byte, layers map[string]bool, t *testing.T) []byte {
out, err := runCopyMVT(input, layers)
if err != nil {
t.Fatalf("CopyMVTLayers(%#v) failed, error: %s", input, err.Error())
}
return out
}
func byteSliceEq(a []byte, b []byte) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func runCopyMVTAssertOutput(input []byte, layers map[string]bool, expected []byte, t *testing.T) {
out := runCopyMVTSuccess(input, layers, t)
if !byteSliceEq(out, expected) {
t.Fatalf("Expected output of CopyMVTLayers(%#v) to be %#v, but instead was %#v", input, expected, out)
}
}
func TestMVTEmptyWithoutLayers(t *testing.T) {
runCopyMVTAssertOutput([]byte{}, map[string]bool{}, []byte{}, t)
}
func TestMVTEmptyWithLayers(t *testing.T) {
runCopyMVTAssertOutput([]byte{}, map[string]bool{"foo": true}, []byte{}, t)
}
func TestMVTNonEmptyWithoutLayers(t *testing.T) {
// has a water layer with a single feature.
mvt := []byte{26, 73, 10, 5, 119, 97, 116, 101, 114, 18, 26, 8, 1, 18, 6, 0, 0, 1, 1, 2, 2, 24, 3, 34, 12, 9, 0, 128, 64, 26, 0, 1, 2, 0, 0, 2, 15, 26, 3, 102, 111, 111, 26, 3, 98, 97, 122, 26, 3, 117, 105, 100, 34, 5, 10, 3, 98, 97, 114, 34, 5, 10, 3, 102, 111, 111, 34, 2, 32, 123, 40, 128, 32, 120, 2}
runCopyMVTAssertOutput(mvt, map[string]bool{}, []byte{}, t)
}
func TestMVTNonEmptyWithLayers(t *testing.T) {
// has a water layer with a single feature.
mvt := []byte{26, 73, 10, 5, 119, 97, 116, 101, 114, 18, 26, 8, 1, 18, 6, 0, 0, 1, 1, 2, 2, 24, 3, 34, 12, 9, 0, 128, 64, 26, 0, 1, 2, 0, 0, 2, 15, 26, 3, 102, 111, 111, 26, 3, 98, 97, 122, 26, 3, 117, 105, 100, 34, 5, 10, 3, 98, 97, 114, 34, 5, 10, 3, 102, 111, 111, 34, 2, 32, 123, 40, 128, 32, 120, 2}
runCopyMVTAssertOutput(mvt, map[string]bool{"water": true}, mvt, t)
}