-
Notifications
You must be signed in to change notification settings - Fork 679
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
How to mock Response without executing a request? #245
Comments
@smiklosovic you could use any http mocking library with Resty to mock request. for e.g. readme reference |
I'm closing this one. |
@jeevatkm no worries, I did this for reference
Then I have some logic around that in my client .. |
@smiklosovic when you set a This quirk makes package main
import (
"fmt"
"io"
"net/http"
"strings"
"github.com/go-resty/resty/v2"
)
func mockResponse(status int, body string) *resty.Response {
rawResponse := new(http.Response)
rawResponse.StatusCode = status
rawResponse.Body = io.NopCloser(strings.NewReader(body))
response := new(resty.Response)
response.RawResponse = rawResponse
return response
}
func main() {
response := mockResponse(200, "body")
body := response.String()
fmt.Printf("Response body is: %v\n", body)
} Have you managed to work around this somehow? |
@Kolyunya @smiklosovic I have added |
@jeevatkm thanks for a quick fix! |
Hey,
I want to test my unmarshalling logic and I do not want to make a call to server, I just want to pretend I already got some response.
body
is package private in Response so how should I set that one?The text was updated successfully, but these errors were encountered: