diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-01-28 14:52:35 -0700 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-01-28 15:01:41 -0700 |
commit | 66a1b1f39a1e1d5499b548b36d18c8daa872d7da (patch) | |
tree | 96471dbd5486ede1a908790ac23e0c55b226dfad /gopher/request_test.go | |
parent | a27b879accb191b6a6c6e76a6251ed751967f73a (diff) |
gopher support.
Some of the contrib packages were originally built gemini-specific and
had to be refactored into generic core functionality and thin
protocol-specific wrappers for each of gemini and gopher.
Diffstat (limited to 'gopher/request_test.go')
-rw-r--r-- | gopher/request_test.go | 43 |
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) + }) + } +} |