query params match irregardless of order
Signed-off-by: Chris Brown <cbrown@pivotal.io>
diff --git a/ghttp/handlers.go b/ghttp/handlers.go
index 8c1668a..424dab5 100644
--- a/ghttp/handlers.go
+++ b/ghttp/handlers.go
@@ -6,6 +6,7 @@
"fmt"
"io/ioutil"
"net/http"
+ "net/url"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
@@ -36,7 +37,10 @@
Ω(req.URL.Path).Should(Equal(path), "Path mismatch")
}
if len(rawQuery) > 0 {
- Ω(req.URL.RawQuery).Should(Equal(rawQuery[0]), "RawQuery mismatch")
+ values, err := url.ParseQuery(rawQuery[0])
+ Ω(err).ShouldNot(HaveOccurred(), "Expected RawQuery is malformed")
+
+ Ω(req.URL.Query()).Should(Equal(values), "RawQuery mismatch")
}
}
}
diff --git a/ghttp/test_server_test.go b/ghttp/test_server_test.go
index 793ca4a..31a2053 100644
--- a/ghttp/test_server_test.go
+++ b/ghttp/test_server_test.go
@@ -4,6 +4,7 @@
"bytes"
"io/ioutil"
"net/http"
+ "net/url"
"regexp"
. "github.com/onsi/ginkgo"
@@ -222,6 +223,18 @@
resp, err = http.Get(s.URL() + "/foo?baz=bar")
Ω(err).ShouldNot(HaveOccurred())
})
+
+ It("should match irregardless of query parameter ordering", func() {
+ s.SetHandler(0, VerifyRequest("GET", "/foo", "type=get&name=money"))
+ u, _ := url.Parse(s.URL() + "/foo")
+ u.RawQuery = url.Values{
+ "type": []string{"get"},
+ "name": []string{"money"},
+ }.Encode()
+
+ resp, err = http.Get(u.String())
+ Ω(err).ShouldNot(HaveOccurred())
+ })
})
Context("when passed a matcher for path", func() {