-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_matcher_test.go
44 lines (35 loc) · 970 Bytes
/
query_matcher_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
package hex
import (
"fmt"
"net/http/httptest"
"testing"
)
func ExampleExpectation_WithQuery() {
e := Expecter{}
e.ExpectReq("GET", "/search").WithQuery("q", "cats")
e.LogReq(httptest.NewRequest("GET", "/search?q=cats", nil))
fmt.Println(e.Summary())
// Output:
// Expectations
// GET /search with query string matching q="cats" - passed
}
func ExampleExpectation_WithQuery_invalidArgument() {
defer func() {
if err := recover(); err != nil {
fmt.Println("Panic:", err)
}
}()
e := Expecter{}
// Unrecognized arguments to WithQuery produce a panic.
e.ExpectReq("GET", "/search").WithQuery(123)
// Output:
// Panic: WithQuery: Cannot use value 123 when matching against url.Values
}
func TestQueryMatcher(t *testing.T) {
e := Expecter{}
e.ExpectReq("GET", "/foo").WithQuery("name", "bob")
e.LogReq(httptest.NewRequest("GET", "/foo?name=bob", nil))
if !e.Pass() {
t.Errorf("WithQuery(\"name\", \"bob\") did not match ?name=bob")
}
}