-
Notifications
You must be signed in to change notification settings - Fork 136
test: add Spanner JSON test suite #1376
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
test: add Spanner JSON test suite #1376
Conversation
…ner-json # Conflicts: # google-cloud-spanner/src/test/java/com/google/cloud/spanner/AbstractStructReaderTypesTest.java # google-cloud-spanner/src/test/java/com/google/cloud/spanner/ResultSetsTest.java
…ner-json # Conflicts: # google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java
…nto spanner-json-test-suit
…ner into spanner-json-test-suit # Conflicts: # google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITJsonWriteReadTest.java # google-cloud-spanner/src/test/resources/com/google/cloud/spanner/it/valid/y_100_nested.json
…nto spanner-json-test-suit # Conflicts: # google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractStructReader.java # google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java # google-cloud-spanner/src/main/java/com/google/cloud/spanner/Value.java # google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java # google-cloud-spanner/src/test/java/com/google/cloud/spanner/ResultSetsTest.java # google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueBinderTest.java # google-cloud-spanner/src/test/java/com/google/cloud/spanner/ValueTest.java # proto-google-cloud-spanner-v1/src/main/java/com/google/spanner/v1/TypeCode.java # proto-google-cloud-spanner-v1/src/main/proto/google/spanner/v1/type.proto
| databaseClient.singleUse().executeQuery(Statement.of("SELECT * FROM " + TABLE_NAME)); | ||
| int count = 0; | ||
| while (resultSet.next()) { | ||
| count++; |
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 think we should either (in order of preference):
- Do a
resultSet.getJson("json")here to verify that the value is also gettable in the client. - Or: Just re-write the query to a
SELECT COUNT(*) ...
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 ended up going with option 2, because the JSON that gets returned is often not the same as what's inserted (e.g. [123e45] gets returned as [1.23e+47]), and it's difficult to automatically determine whether the returned value is equivalent to the inserted value without the same library that the backend uses to parse JSON. Since the tests are only there to confirm that the backend is able to accept the valid values, I don't think I'll bother spending the extra time manually adding the expected results for each file. Hopefully this is okay!
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITJsonWriteReadTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITJsonWriteReadTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITJsonWriteReadTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java
Outdated
Show resolved
Hide resolved
…nto spanner-json-test-suit
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITJsonWriteReadTest.java
Outdated
Show resolved
Hide resolved
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.
LGTM
| .singleUse() | ||
| .executeQuery(Statement.of("SELECT COUNT(*) FROM " + TABLE_NAME))) { | ||
| resultSet.next(); | ||
| assertEquals(resultSet.getLong(0), resources.size()); |
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 validate the JSON string as well?
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.
We had a discussion about this above: #1376 (comment)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️