46 lines
932 B
Go
46 lines
932 B
Go
package spartan_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"tildegit.org/tjp/gus/spartan"
|
|
)
|
|
|
|
func TestParseRequest(t *testing.T) {
|
|
tests := []struct {
|
|
requestLine string
|
|
host string
|
|
path string
|
|
clen int
|
|
}{
|
|
{
|
|
requestLine: "foobar.ninja /baz/quux 0\r\n",
|
|
host: "foobar.ninja",
|
|
path: "/baz/quux",
|
|
clen: 0,
|
|
},
|
|
{
|
|
requestLine: "foo.bar / 12\r\n",
|
|
host: "foo.bar",
|
|
path: "/",
|
|
clen: 12,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.requestLine, func(t *testing.T) {
|
|
request, clen, err := spartan.ParseRequest(bytes.NewBufferString(test.requestLine))
|
|
require.Nil(t, err)
|
|
|
|
assert.Equal(t, test.host, request.Host)
|
|
assert.Equal(t, test.path, request.Path)
|
|
assert.Equal(t, test.path, request.RawPath)
|
|
assert.Equal(t, test.clen, clen)
|
|
})
|
|
}
|
|
}
|