Conversation
|
Hi ! |
brackendawson
left a comment
There was a problem hiding this comment.
This is a good implementation.
I have questions about whether JSONEq should have ever been added. My preference would always be your API should yield stably formatted output. If JSONEq should have been added then it should have always accepted a []byte rather than a string. I'm not going to merge this without input from other maintainers, any thoughts @dolmen?
It would be useful to see if there is a real world example where the string is prohibitively expensive.
|
@GCrispino can you re-base to run the latest version of the tests. |
|
I note that YAMLEq also accepts a string, that's an even more problematic assertion. |
c1830b9 to
528f908
Compare
528f908 to
29a3e3b
Compare
|
@brackendawson rebased my branch against master and re ran |
brackendawson
left a comment
There was a problem hiding this comment.
Still approve, as per my previous comments.
|
@brackendawson thanks! Is there something else I should do, or are you only expecting review from another maintainer? |
Nothing else needed from you at this time, just wait for another maintainer to opine. |
|
Note to self: push merge conflict resolve this is one nice addition in a million. The string stuff should never have existed in the first place but let’s be pragmatic and adopt one api that we test writers may use idiomatically, ie without type conversion |
df6d47d
29a3e3b to
df6d47d
Compare
df6d47d to
aa741a8
Compare
|
Hi @fredbi ! I have gone ahead and solved the merge conflicts myself. I believe it's all good, as tests are passing. |
Resolved merge conflicts with the go-openapi fork, rebase and ensured all tests pass. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
assert/cpu.out
Outdated
There was a problem hiding this comment.
We probably don't need this cpu.out file.
There was a problem hiding this comment.
Sorry, I hadn't realized I had added that file. Pushed a commit removing it 👍🏼
|
@GCrispino merged in our fork go-openapi/testify |
dolmen
left a comment
There was a problem hiding this comment.
We must have special messages for the []byte(nil) cases.
Currently if I've added a commit that will use the messages of Can you please have a look at it? |
|
@GCrispino I think you quoted me while you wanted to quote @dolmen |
|
@ccoVeille oh yeah sorry, that was the case indeed 😅 , thanks for the heads up |
Summary
This PR adds a new function into the
assertpackage,JSONEqBytes, that does the same asJSONEq, but by receiving[]bytevalues as parameter instead ofstringones.Changes
assert/assertions.go:The implementation of
JSONEqBytesis pretty much what was inJSONEq, but having it receive[]bytevalues and then not needing to convert these values to[]bytewhen callingjson.Unmarshalinside it.Then, the implementation of
JSONEqwas changed such that it just callsJSONEqBytesby converting its original arguments to[]bytevalues (which it already did when callingjson.Unmarshal)assert/assertions_test.go:Tests for
JSONEqBytesfunction were replicated from the tests fromJSONEq.Motivation
It is common in Go to store JSON text in
[]bytevariables instead ofstringvalues, so having a function that allows to receive these values when doing JSON-equality checks without having to cast them to string can be useful.Maybe not as important, it would also avoid unnecessary
[]byte-to-stringconversions, which could add up when dealing with big JSON payloads.Example of usage: