summaryrefslogtreecommitdiff
path: root/gopher/request_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'gopher/request_test.go')
-rw-r--r--gopher/request_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/gopher/request_test.go b/gopher/request_test.go
new file mode 100644
index 0000000..1ab7801
--- /dev/null
+++ b/gopher/request_test.go
@@ -0,0 +1,43 @@
+package gopher_test
+
+import (
+ "bytes"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ "tildegit.org/tjp/gus/gopher"
+)
+
+func TestParseRequest(t *testing.T) {
+ tests := []struct {
+ requestLine string
+ path string
+ query string
+ }{
+ {
+ requestLine: "\r\n",
+ path: "/",
+ },
+ {
+ requestLine: "foo/bar\r\n",
+ path: "/foo/bar",
+ },
+ {
+ requestLine: "search\tthis AND that\r\n",
+ path: "/search",
+ query: "this+AND+that",
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.requestLine, func(t *testing.T) {
+ request, err := gopher.ParseRequest(bytes.NewBufferString(test.requestLine))
+ require.Nil(t, err)
+
+ assert.Equal(t, test.path, request.Path)
+ assert.Equal(t, test.query, request.RawQuery)
+ })
+ }
+}