forked from go-fuego/fuego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.go
33 lines (27 loc) · 910 Bytes
/
validation_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
package fuego
import (
"testing"
"github.com/stretchr/testify/require"
)
type validatableStruct struct {
Name string `validate:"required,min=3,max=10"`
Age int `validate:"min=18"`
Required string `validate:"required"`
Email string `validate:"email"`
ExternalID string `validate:"uuid"`
}
func TestValidate(t *testing.T) {
me := validatableStruct{
Name: "Napoleon Bonaparte",
Age: 12,
Email: "napoleon.bonaparte",
}
err := validate(me)
t.Log(err)
require.Error(t, err)
var errStructValidation HTTPError
require.ErrorAs(t, err, &errStructValidation)
require.Equal(t, 400, errStructValidation.StatusCode())
require.Equal(t, "400 Validation Error: Name should be max=10, Age should be min=18, Required is required, Email should be a valid email, ExternalID should be a valid UUID", errStructValidation.Error())
require.Len(t, errStructValidation.Errors, 5)
}