diff --git a/internal/integration/all_of_test.go b/internal/integration/all_of_test.go index 083ab59ae..907974b0b 100644 --- a/internal/integration/all_of_test.go +++ b/internal/integration/all_of_test.go @@ -2,6 +2,7 @@ package integration import ( "context" + "fmt" "net/http/httptest" "strings" "testing" @@ -50,15 +51,27 @@ func TestAllof(t *testing.T) { require.NoError(t, err) } + regexPattern := "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + ctx := context.Background() t.Run("nullableStrings", func(t *testing.T) { err := client.NullableStrings(ctx, api.NilString{}) - _, ok := errors.Into[*validate.NoRegexMatchError](err) + regexMatchErr, ok := errors.Into[*validate.NoRegexMatchError](err) require.True(t, ok, "validate: string: no regex match") + require.ErrorContains( + t, + regexMatchErr, + fmt.Sprintf("no regex match: %s", regexPattern), + ) err = client.NullableStrings(ctx, api.NewNilString("foo")) - _, ok = errors.Into[*validate.NoRegexMatchError](err) + regexMatchErr, ok = errors.Into[*validate.NoRegexMatchError](err) require.True(t, ok, "validate: string: no regex match") + require.ErrorContains( + t, + regexMatchErr, + fmt.Sprintf("no regex match: %s", regexPattern), + ) err = client.NullableStrings(ctx, api.NewNilString("127.0.0.1")) require.NoError(t, err) diff --git a/validate/errors.go b/validate/errors.go index 7d6d7c595..42240b693 100644 --- a/validate/errors.go +++ b/validate/errors.go @@ -2,6 +2,7 @@ package validate import ( "fmt" + "github.com/ogen-go/ogen/ogenregex" "strings" "github.com/go-faster/errors" @@ -102,9 +103,11 @@ func (e *MaxLengthError) Error() string { } // NoRegexMatchError reports that value have no regexp match. -type NoRegexMatchError struct{} +type NoRegexMatchError struct { + Pattern ogenregex.Regexp +} // MaxLengthError implements error. -func (*NoRegexMatchError) Error() string { - return "no regex match" +func (e *NoRegexMatchError) Error() string { + return fmt.Sprintf("no regex match: %s", e.Pattern.String()) } diff --git a/validate/string.go b/validate/string.go index 5314b5602..1ecf3f617 100644 --- a/validate/string.go +++ b/validate/string.go @@ -124,7 +124,9 @@ func (t String) Validate(v string) error { return errors.Wrap(err, "execute regex") } if !match { - return &NoRegexMatchError{} + return &NoRegexMatchError{ + Pattern: r, + } } } return nil