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

client: setters for JSON and XML Marshal/Unmarshal #621

Merged
merged 2 commits into from
Mar 11, 2023

Conversation

GRbit
Copy link
Contributor

@GRbit GRbit commented Feb 27, 2023

Today I learned that I can set external JSON library for resty to marshal JSON faster. It wasn't so obvious because I haven't read the docs (let's be honest it's not only me who doesn't read docs), but there was no method for resty.Client to override JSON marshal function.

I suggest adding these Set* functions because this way they will be available through IDEs auto-completion.

@codecov
Copy link

codecov bot commented Mar 6, 2023

Codecov Report

Merging #621 (5b6825f) into master (9e2a9b7) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #621      +/-   ##
==========================================
- Coverage   95.94%   95.91%   -0.04%     
==========================================
  Files          10       10              
  Lines        1357     1395      +38     
==========================================
+ Hits         1302     1338      +36     
- Misses         34       35       +1     
- Partials       21       22       +1     
Impacted Files Coverage Δ
client.go 97.90% <100.00%> (+0.13%) ⬆️
middleware.go 90.64% <0.00%> (-0.63%) ⬇️
retry.go 100.00% <0.00%> (ø)
request.go 95.47% <0.00%> (ø)
redirect.go 94.11% <0.00%> (ø)
response.go 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GRbit Thanks for your PR. Your PR description put a smile on my face, thanks.

Can you please add test cases for this PR? see here for more info

@GRbit
Copy link
Contributor Author

GRbit commented Mar 6, 2023

@jeevatkm I'm glad that it makes you smile.

Sorry for taking your time on that, but could you please tell me what kind of tests should I do? The only test I can come up with is something like this:

func TestClientJSON(t *testing.T) {
	m := func (v interface{}) ([]byte, error) { return nil,nil }
	c := New().SetJSONMarshaler(m)
	assertEqual(t, m, c.JSONMarshal)
}

But it looks silly for me to test such things because I don't think this test could possibly be helpful.

If this is what you looking for – I'll be glad to add a test for each function. If not, please show me some examples in the code

@jeevatkm
Copy link
Member

jeevatkm commented Mar 8, 2023

@GRbit Thanks for the getting back.

@jeevatkm I'm glad that it makes you smile.

Sorry for taking your time on that ...

Just to be clear, why I mentioned about smile is regarding this part from the PR description. Because, time-to-time, I also do the same!

(let's be honest it's not only me who doesn't read docs)


I understand, what you mean. However, based on the PR context, we are introducing a new setter methods for populating certain field. So it make sense to add a tiny test case which calls those setter(s) and does the assertion.

@GRbit
Copy link
Contributor Author

GRbit commented Mar 9, 2023

@jeevatkm I respect your standards, so my only question was "how should I make those tests?". Please check out the code I've just added, I hope it's ok.

Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @GRbit for your contribution.

@jeevatkm jeevatkm merged commit e88d44d into go-resty:master Mar 11, 2023
@jeevatkm jeevatkm added this to the v2.8.0 Milestone milestone Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants