diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-01-09 16:40:24 -0700 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-01-09 16:40:24 -0700 |
commit | ff05d62013906f3086b452bfeda3e0d5b9b7a541 (patch) | |
tree | 3be29de0b1bc7c273041c6d89b71ca447c940556 /gemini/request_test.go |
Initial commit.
some basics:
- minimal README
- some TODOs
- server and request handler framework
- contribs: file serving, request logging
- server examples
- CI setup
Diffstat (limited to 'gemini/request_test.go')
-rw-r--r-- | gemini/request_test.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/gemini/request_test.go b/gemini/request_test.go new file mode 100644 index 0000000..1da24f7 --- /dev/null +++ b/gemini/request_test.go @@ -0,0 +1,86 @@ +package gemini_test + +import ( + "bytes" + "testing" + + "tildegit.org/tjp/gus/gemini" +) + +func TestParseRequest(t *testing.T) { + table := []struct { + input string + scheme string + host string + path string + query string + fragment string + err error + }{ + { + input: "gemini://foo.com/bar?baz#qux\r\n", + scheme: "gemini", + host: "foo.com", + path: "/bar", + query: "baz", + fragment: "qux", + err: nil, + }, + { + input: "//foo.com/path\r\n", + scheme: "gemini", + host: "foo.com", + path: "/path", + query: "", + fragment: "", + err: nil, + }, + { + input: "/path\r\n", + scheme: "gemini", + host: "", + path: "/path", + query: "", + fragment: "", + err: nil, + }, + { + input: "gemini://invalid.com/line/ending", + scheme: "", + host: "", + path: "", + query: "", + fragment: "", + err: gemini.InvalidRequestLineEnding, + }, + } + + for _, test := range table { + t.Run(test.input, func(t *testing.T) { + req, err := gemini.ParseRequest(bytes.NewBufferString(test.input)) + if err != test.err { + t.Fatalf("expected error %q, got %q", test.err, err) + } + + if err != nil { + return + } + + if req.Scheme != test.scheme { + t.Errorf("expected scheme %q, got %q", test.scheme, req.Scheme) + } + if req.Host != test.host { + t.Errorf("expected host %q, got %q", test.host, req.Host) + } + if req.Path != test.path { + t.Errorf("expected path %q, got %q", test.path, req.Path) + } + if req.RawQuery != test.query { + t.Errorf("expected query %q, got %q", test.query, req.RawQuery) + } + if req.Fragment != test.fragment { + t.Errorf("expected fragment %q, got %q", test.fragment, req.Fragment) + } + }) + } +} |