Skip to content

Commit

Permalink
Adding more Geom tests. (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored May 8, 2024
1 parent 30e1877 commit f4e2e06
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions lib/postgres/parse/geom_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package parse

import (
"github.com/artie-labs/transfer/lib/debezium"
"testing"

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

func TestToPoint(t *testing.T) {
tcs := []struct {
name string
input string
output *Point
expectedErr string
name string
input string
output *Point
expectedOutput string
expectedErr string
}{
{
name: "Valid point",
input: "(2.2945,48.8584)",
output: &Point{X: 2.2945, Y: 48.8584},
name: "Valid point",
input: "(2.2945,48.8584)",
expectedOutput: `{"type":"Feature","geometry":{"type":"Point","coordinates":[2.2945,48.8584]}}`,
output: &Point{X: 2.2945, Y: 48.8584},
},
{
name: "Invalid format",
Expand Down Expand Up @@ -46,33 +49,41 @@ func TestToPoint(t *testing.T) {
assert.ErrorContains(t, err, tc.expectedErr, tc.name)
} else {
assert.Equal(t, *tc.output, *point, tc.name)

val, err := debezium.Field{DebeziumType: debezium.GeometryPointType}.ParseValue(point.ToMap())
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, val, tc.name)
}
}
}

func TestToGeography(t *testing.T) {
// TODO: We should make Transfer's `parseValue` function public so we can test for parsing symmetry
{
data := []byte("010100000000000000000000000000000000000000")
expected, err := ToGeography(data)
geoData, err := ToGeography(data)
assert.NoError(t, err)

// This is Point (0,0)
assert.Equal(t, map[string]any{
"wkb": "AQEAAAAAAAAAAAAAAAAAAAAAAAAA",
"srid": nil,
}, expected)
}, geoData)

val, err := debezium.Field{DebeziumType: debezium.GeometryType}.ParseValue(geoData)
assert.NoError(t, err)
assert.Equal(t, `{"type":"Feature","geometry":{"type":"Point","coordinates":[0,0]},"properties":null}`, val)
}

{
data := []byte("0101000000000000000000F03F000000000000F03F")
expected, err := ToGeography(data)
geoData, err := ToGeography(data)
assert.NoError(t, err)

// This is Point (1,1)
assert.Equal(t, map[string]any{
"wkb": "AQEAAAAAAAAAAADwPwAAAAAAAPA/",
"srid": nil,
}, expected)
}, geoData)

val, err := debezium.Field{DebeziumType: debezium.GeometryType}.ParseValue(geoData)
assert.NoError(t, err)
assert.Equal(t, `{"type":"Feature","geometry":{"type":"Point","coordinates":[1,1]},"properties":null}`, val)
}
}

0 comments on commit f4e2e06

Please sign in to comment.