forked from ComboStrikeHQ/vcr-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
util_test.go
38 lines (30 loc) · 866 Bytes
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package httpvcr
import (
"bytes"
"io/ioutil"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestModifyHTTPRequestBody(t *testing.T) {
req, err := http.NewRequest("GET", "/", bytes.NewBufferString("abc"))
assert.Nil(t, err)
assert.Equal(t, int64(3), req.ContentLength)
ModifyHTTPRequestBody(req, func(input string) string {
assert.Equal(t, input, "abc")
return "foofoo"
})
assert.Equal(t, int64(6), req.ContentLength)
body, _ := ioutil.ReadAll(req.Body)
assert.Equal(t, "foofoo", string(body))
}
func TestModifyHTTPRequestBodyWithNilBody(t *testing.T) {
req, err := http.NewRequest("GET", "/", nil)
assert.Nil(t, err)
assert.Equal(t, int64(0), req.ContentLength)
ModifyHTTPRequestBody(req, func(input string) string {
return "foofoo"
})
assert.Equal(t, int64(0), req.ContentLength)
assert.Equal(t, req.Body, nil)
}