vitorestevam / FluentRequest

A friendly http wrapper
3 stars 1 forks source link

Add ExpectedStatusCode to handle status expectations #7

Open vitorestevam opened 1 year ago

vitorestevam commented 1 year ago

The idea is having a call where we can pass the http status codes we want. If the expectation is not met, then an error should be returned

example:

resp, err := FluentRequest().
                Method("GET").
                Url("https://jsonplaceholder.typicode.com/todos/1").
                ExpectedStatus("200","202").
                Run()
xTecna commented 1 year ago

Hello, can I take this one?

In fact, I've already implemented the functionality, but wasn't able to test it yet because now it needs to return something different than success, there are errors involved, so I will need more time to fit it to the existing structure of tests. Which would be the best alternatives of doing this? Would you like to separate a new function for functions that expect an error?

Also, if you may, please, can you help me to understand know can I test variadic functions in it?

Thank you for your attention.

vitorestevam commented 1 year ago

To get the "bad responses" with any kind of status codes you can use this website: https://httpstat.us/. You just need to pass the status code you want to receive like this https://httpstat.us/404

vitorestevam commented 1 year ago

I think you can create a new test function"TestRequestWithExpected" just like "TestRequest". Maybe this kind of name can become a pattern for future tests, but feel free to suggest a better name.

if you are going to create more than on testCase preffer using table driven tests following the pattern of "TestRequest", but for this i do think you need to create many tests.

vitorestevam commented 1 year ago

I did not understand what you want to know about variadic functions, but go better example might help you. https://gobyexample.com/variadic-functions

if you still with trouble on it, please let me know