-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_test.go
47 lines (36 loc) · 1.16 KB
/
query_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
package serv
import (
"net/http/httptest"
"testing"
)
func TestQuery(t *testing.T) {
req := httptest.NewRequest("GET", "/123/13241234?test=1&login=monster&pt=true&pt=p2&wsdl&f=false", nil)
if req == nil {
t.Fatal("test request create failed")
}
qw := newQuery(req)
if qw == nil {
t.Fatal("newQuery failed")
}
if qw.Has("unknown") {
t.Fatal("Has return true for unknown param")
}
if !qw.Has("test") || !qw.Has("login") || !qw.Has("wsdl") {
t.Fatal("Not found all fields")
}
if qw.GetInt64("unknown") != 0 || qw.GetInt64("test") != 1 || qw.GetInt64("wsdl") != 0 {
t.Fatal("GetInt64 failed")
}
if qw.GetInt("unknown") != 0 || qw.GetInt("test") != 1 || qw.GetInt("wsdl") != 0 {
t.Fatal("GetInt failed")
}
if qw.GetFloat("unknown") != 0 || qw.GetFloat("test") != 1 || qw.GetFloat("wsdl") != 0 {
t.Fatal("GetFloat failed")
}
if qw.GetString("unknown") != "" || qw.GetString("test") != "1" || qw.GetString("wsdl") != "" || qw.GetString("f") != "false" {
t.Fatal("GetFloat failed")
}
if qw.GetBool("unknown") || !qw.GetBool("test") || qw.GetBool("wsdl") || qw.GetBool("f") || !qw.GetBool("test") || !qw.GetBool("pt") {
t.Fatal("GetBool failed")
}
}