Repository navigation
Added type handler for jsonpath - #3177
Conversation
roji
left a comment
There was a problem hiding this comment.
Am a bit confused in the tests but other LGTM.
There was a problem hiding this comment.
Is there a need for us to test different cases here? After all Npgsql is just reading and writing strings here and doesn't interact with the content in any way... If that's the case, I'd consider just embedding any same query (one of the below) in the tests themselves for simplification
There was a problem hiding this comment.
An experiment, looking for unification of our type handlers tests, so in the final they should just accept cases and have test methods in the base class like in benchmarks. No boilerplate code, just cases.
Take a look at the numeric test class or money, for an example.
There was a problem hiding this comment.
The difference is that in numeric there really are different cases for us to test, because they trigger different code paths inside the handler. With jsonpath we are just passing a string..
There was a problem hiding this comment.
Yes, but the idea is to have a common base for all type tests. Doesn't matter what is going to be tested, it tested the same way.
There was a problem hiding this comment.
I'm not sure I see the point of that. Am OK for merging as-is, but maybe better to do test cases when we actually apply the common base?
If you want to keep this, is anything additional being tested by having two test cases? Why not just keep one? I'm asking because the test gives the impression that we actually care what's in those strings.
There was a problem hiding this comment.
The next step is to start test unification, so the answer to your question is no (:
To see why I added the second case, just remove double quotes from the query string and see what happens. While jsonpath is transferred as a C string prefixed by a version number, the internal representation isn't a string and casting it back could give a different result.
There was a problem hiding this comment.
nit: can also write Assert.True which I find slightly more clear, but really not important.
There was a problem hiding this comment.
This test verifies that the server correctly parsed the parameter and it has the same values the unlined into the query. Otherwise, reading the passed parameter may hide a possible bug because of a symmetric in Write.
There was a problem hiding this comment.
I agree it's a good idea to split reading and writing tests (and we don't do that with many types).
But specifically here, isn't it enough to just do SELECT @p::text and assert on the returned text representation? That would be a 100% reliable test of the sending, no?
There was a problem hiding this comment.
In that case we will rely on the behavior of TextHandler which could have a bug too.
There was a problem hiding this comment.
I think it's ok to assume that TextHandler works in this test, no? After all you're relying on BoolHandler not having bugs in the exact same way
There was a problem hiding this comment.
Fixed, it doesn't rely on other handlers any more.
Co-authored-by: Shay Rojansky <[email protected]>
roji
left a comment
There was a problem hiding this comment.
OK for merging but see my remaining test comments.
There was a problem hiding this comment.
I'm not sure I see the point of that. Am OK for merging as-is, but maybe better to do test cases when we actually apply the common base?
If you want to keep this, is anything additional being tested by having two test cases? Why not just keep one? I'm asking because the test gives the impression that we actually care what's in those strings.
| using var conn = await OpenConnectionAsync(); | ||
| MinimumPgVersion(conn, "12.0", "The jsonpath type was introduced in PostgreSQL 12"); | ||
|
|
||
| using var cmd = new NpgsqlCommand($"SELECT 'Passed' WHERE @p::text = {query}::text", conn) { Parameters = { new NpgsqlParameter("p", NpgsqlDbType.JsonPath) { Value = expected } } }; |
There was a problem hiding this comment.
Am OK for merging, but I still don't understand the point of this compared to just SELECT @p::text and asserting on the returned string - it's needlessly complicated.
There was a problem hiding this comment.
We don't use other handlers and we should have more reliable tests. Plus keep in mind that I told you in other thread, I want to unify tests, so it won't work well for floating point numbers and you know why.
Fixes #2504