Skip to content

Commit

Permalink
Test header and readPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
shaxbee committed Apr 20, 2016
1 parent 4b18cf9 commit 470d211
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions wkb/point_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wkb

import (
"encoding/binary"
"encoding/hex"
"testing"

Expand Down Expand Up @@ -95,3 +96,17 @@ func TestMultipoint(t *testing.T) {
assert.Equal(t, Point{30, 10}, mp[3])
}
}

func TestReadPoints(t *testing.T) {
invalid := [][]byte{
{0x01, 0x00, 0x00}, // numpoints too short
{0x01, 0x00, 0x00, 0x00}, // no payload
}

for _, b := range invalid {
_, _, err := readPoints(b, binary.LittleEndian)
if assert.Error(t, err) {
assert.Exactly(t, ErrInvalidStorage, err)
}
}
}
32 changes: 32 additions & 0 deletions wkb/primitive_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package wkb

import (
"encoding/binary"
"testing"

"github.com/stretchr/testify/assert"
)

func TestHeader(t *testing.T) {
if _, _, err := header("", 0); assert.Error(t, err) {
assert.Exactly(t, ErrInvalidStorage, err, "should fail for non-[]byte type")
}

invalid := map[error][]byte{
ErrInvalidStorage: {},
ErrInvalidStorage: {0x01},
ErrUnsupportedValue: {0x02, 0x01, 0x00, 0x00, 0x00},
ErrUnsupportedValue: {0x01, 0x02, 0x00, 0x00, 0x00},
}
for expected, b := range invalid {
if _, _, err := header(b, GeomPoint); assert.Error(t, err) {
assert.Exactly(t, expected, err)
}
}

valid := []byte{0x01, 0x01, 0x00, 0x00, 0x00}
if b, bo, err := header(valid, GeomPoint); assert.NoError(t, err) {
assert.Len(t, b, 0)
assert.Exactly(t, binary.LittleEndian, bo)
}
}

0 comments on commit 470d211

Please sign in to comment.