-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Body not repeat #35
Comments
Solve specific problems package main
import (
"io"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/vitorsalgado/mocha/v3"
"github.com/vitorsalgado/mocha/v3/expect"
"github.com/vitorsalgado/mocha/v3/params"
"github.com/vitorsalgado/mocha/v3/reply"
)
func TestSeqReply(t *testing.T) {
m := mocha.New(t)
m.Start()
m.AddMocks(mocha.Get(expect.URLPath("/test")).Repeat(2).ReplyFunction(func(request *http.Request, m reply.M, p params.P) (*reply.Response, error) {
r := strings.NewReader("Hello")
return &reply.Response{
Status: http.StatusOK,
Body: r,
}, nil
}))
req, _ := http.NewRequest(http.MethodGet, m.URL()+"/test", nil)
{
res, err := http.DefaultClient.Do(req)
assert.Nil(t, err)
assert.Equal(t, 200, res.StatusCode)
b, err := io.ReadAll(res.Body)
assert.Nil(t, err)
assert.Equal(t, []byte("Hello"), b)
}
{
res, err := http.DefaultClient.Do(req)
assert.Nil(t, err)
assert.Equal(t, 200, res.StatusCode)
b, err := io.ReadAll(res.Body)
assert.Nil(t, err)
assert.Equal(t, []byte("Hello"), b)
}
}
|
rpprabha1
added a commit
to rpprabha1/mocha
that referenced
this issue
Aug 23, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I'm trying to setup a mock server with 2 replies for the same URL Path, but 2nd request no body From what I could gather from the lib examples, I believe this should have worked
To Reproduce
Run the following test
Expected behavior
Test should run with no errors
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: