Skip to content
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

Merged

Conversation

peterstace
Copy link
Owner

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

This ensures that coordinate types are consistent between the geometry
collection and its children.
@peterstace peterstace self-assigned this May 14, 2024
if gc.ct == point.ct {
expectNoErr(t, err)
} else {
expectErr(t, err)
Copy link
Collaborator

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?

Copy link
Owner Author

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).

Copy link
Owner Author

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.

Copy link
Owner Author

@peterstace peterstace May 15, 2024

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).

Base automatically changed from issue_397_check_geometry_collection_coord_types to master May 15, 2024 19:08
@peterstace
Copy link
Owner Author

Thanks for reviewing!

@peterstace peterstace merged commit d1a3d0b into master May 15, 2024
1 check passed
@peterstace peterstace deleted the issue_397_check_geometry_collection_coord_types_for_wkb branch May 15, 2024 19:13
peterstace added a commit that referenced this pull request May 15, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants