|
@@ -354,6 +354,14 @@ func TestParseWithValidatorWithError(t *testing.T) {
|
|
assert.Error(t, Parse(r, &v))
|
|
assert.Error(t, Parse(r, &v))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestParseWithValidatorRequest(t *testing.T) {
|
|
|
|
+ SetValidator(mockValidator{})
|
|
|
|
+ var v mockRequest
|
|
|
|
+ r, err := http.NewRequest(http.MethodGet, "/a?&age=18", http.NoBody)
|
|
|
|
+ assert.Nil(t, err)
|
|
|
|
+ assert.Error(t, Parse(r, &v))
|
|
|
|
+}
|
|
|
|
+
|
|
func BenchmarkParseRaw(b *testing.B) {
|
|
func BenchmarkParseRaw(b *testing.B) {
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", http.NoBody)
|
|
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", http.NoBody)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -410,3 +418,15 @@ func (m mockValidator) Validate(r *http.Request, data any) error {
|
|
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+type mockRequest struct {
|
|
|
|
+ Name string `json:"name,optional"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m mockRequest) Validate() error {
|
|
|
|
+ if m.Name != "hello" {
|
|
|
|
+ return errors.New("name is not hello")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|