-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
request_test.go
52 lines (43 loc) · 1.03 KB
/
request_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2021 Flamego. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package flamego
import (
"bytes"
"io"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRequest(t *testing.T) {
t.Run("bytes", func(t *testing.T) {
r := Request{
Request: &http.Request{
Body: io.NopCloser(bytes.NewReader([]byte("foobar"))),
},
}
body, err := r.Body().Bytes()
assert.Nil(t, err)
assert.Equal(t, []byte("foobar"), body)
})
t.Run("string", func(t *testing.T) {
r := Request{
Request: &http.Request{
Body: io.NopCloser(bytes.NewReader([]byte("foobar"))),
},
}
body, err := r.Body().String()
assert.Nil(t, err)
assert.Equal(t, "foobar", body)
})
t.Run("ReadCloser", func(t *testing.T) {
r := Request{
Request: &http.Request{
Body: io.NopCloser(bytes.NewReader([]byte("foobar"))),
},
}
body, err := io.ReadAll(r.Body().ReadCloser())
assert.Nil(t, err)
assert.Equal(t, []byte("foobar"), body)
})
}