-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #21 context.Query().Has(param)
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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") | ||
} | ||
} |