-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dimension check when parsing WKB GeometryCollections #615
Add dimension check when parsing WKB GeometryCollections #615
Conversation
This ensures that coordinate types are consistent between the geometry collection and its children.
if gc.ct == point.ct { | ||
expectNoErr(t, err) | ||
} else { | ||
expectErr(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we assert that the error type is mismatchedGeometryCollectionDimsError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory that would be ideal. However, mismatchedGeometryCollectionDimsError
is not exported, so not available in the geom_test
package. So we'd either have to:
- Export the error type (I don't want to do that since it's creating more API surface area that makes things harder to change in the future).
- Run the tests in the
geom
package (I also don't want to do that since I prefer to test only the public interface and have that enforced). - Miss the
error.Is
assertion (I think that's the best option out of the three, although not ideal).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually.... maybe there is a way to get the best of both worlds. I'll do some experimentation and raise a fix in a new PR if I can get it working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried something out in #616 (it seems to work pretty well, would love to get your opinion).
Thanks for reviewing! |
This change introduces better error assertions, prompted by a comment from Albert Teoh here: #615 (comment) The change introduces two new test helper functions: - expectErrIs(tb testing.TB, err, want error) - expectErrAs(tb testing.TB, err error, target interface{}) These wrap `errors.Is` and `errors.As` functions from the standard library, respectively. In order for this to work, the `mismatchedGeometryCollectionDimsError` must be exported, but _only during tests_ (because we don't want to expose it to users of the library). This is achieved by using type aliases in a `_test.go` file in the `geom` package. Because `_test.go` files are only included during tests, this is a safe way to expose the type only during tests.
Description
Add dimension check when parsing WKB GeometryCollections
This ensures that coordinate types are consistent between the geometry collection and its children.
Check List
Have you:
Added unit tests? Yes.
Add cmprefimpl tests? (if appropriate?) N/A
Updated release notes? (if appropriate?) Yes.
Related Issue