forked from miku/metha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
76 lines (72 loc) · 1.9 KB
/
request_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package metha
import (
"net/url"
"testing"
)
func mustParseURL(s string) *url.URL {
u, err := url.Parse(s)
if err != nil {
panic(err)
}
return u
}
func TestURL(t *testing.T) {
var tests = []struct {
req Request
u *url.URL
err error
}{
{req: Request{}, u: nil, err: ErrMissingURL},
{req: Request{Verb: "x"}, u: nil, err: ErrMissingURL},
{req: Request{
BaseURL: "x",
Verb: "x",
}, u: nil, err: ErrInvalidVerb},
{req: Request{
BaseURL: "http://example.com",
Verb: "x",
}, u: nil, err: ErrInvalidVerb},
{req: Request{
BaseURL: "http://example.com",
Verb: "Identify",
}, u: mustParseURL("http://example.com?verb=Identify"), err: nil},
{req: Request{
BaseURL: "http://example.com",
Verb: "ListRecords",
}, u: nil, err: ErrParameterMissing},
{req: Request{
BaseURL: "http://example.com",
Verb: "ListRecords",
Set: "x",
}, u: nil, err: ErrParameterMissing},
{req: Request{
BaseURL: "http://example.com",
Verb: "ListRecords",
MetadataPrefix: "x",
}, u: mustParseURL("http://example.com?metadataPrefix=x&verb=ListRecords"), err: nil},
{req: Request{
BaseURL: "http://example.com",
Verb: "ListRecords",
MetadataPrefix: "x",
From: "20",
}, u: mustParseURL("http://example.com?from=20&metadataPrefix=x&verb=ListRecords"), err: nil},
{req: Request{
BaseURL: "http://example.com",
Verb: "ListRecords",
MetadataPrefix: "x",
From: "20",
ResumptionToken: "1",
}, u: mustParseURL("http://example.com?resumptionToken=1&verb=ListRecords"), err: nil},
}
for _, test := range tests {
u, err := test.req.URL()
if err != test.err {
t.Errorf("req.URL(%+v), got %v, want %v", test.req, err, test.err)
}
if err == nil {
if u.String() != test.u.String() {
t.Errorf("req.URL(%+v), got %v, want %v", test.req, u, test.u)
}
}
}
}