Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Apr 24, 2020
1 parent 3f1a1f4 commit ec13252
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions bytes/seekable/seekable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,50 @@ import (
"bytes"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func assertEqual(t *testing.T, a, b interface{}) {
if a != b {
t.Fatal("assertEqual:", a, b)
}
}

func assertNoError(t *testing.T, err error) {
if err != nil {
t.Fatal("assertNoError:", err)
}
}

func TestSeekable_EOFIfReqAlreadyParsed(t *testing.T) {
body := "a=1"
req, err := http.NewRequest("POST", "/a", bytes.NewBufferString(body))
assert.NoError(t, err)
assertNoError(t, err)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Length", "3")
req.ParseForm()
_, err = New(req)
assert.Equal(t, err.Error(), "EOF")
assertEqual(t, err.Error(), "EOF")
}

func TestSeekable_WorkaroundForEOF(t *testing.T) {
body := "a=1"
req, err := http.NewRequest("POST", "/a", bytes.NewBufferString(body))
assert.NoError(t, err)
assertNoError(t, err)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Length", "3")
_, _ = New(req)
req.ParseForm()
assert.Equal(t, req.FormValue("a"), "1")
assertEqual(t, req.FormValue("a"), "1")
_, err = New(req)
assert.NoError(t, err)
assertNoError(t, err)
}

func TestSeekable(t *testing.T) {
body := "a=1"
req, err := http.NewRequest("POST", "/a", bytes.NewBufferString(body))
assert.NoError(t, err)
assertNoError(t, err)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Content-Length", "3")
_, err = New(req)
assert.NoError(t, err)
assertNoError(t, err)
}

0 comments on commit ec13252

Please sign in to comment.