-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator_test.go
More file actions
44 lines (37 loc) · 1.02 KB
/
Copy pathvalidator_test.go
File metadata and controls
44 lines (37 loc) · 1.02 KB
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 validator_test
import (
"testing"
"time"
"github.com/oSethoum/validator"
)
type BaseModel struct {
ID string `json:"id,omitempty" gorm:"primaryKey" validate:"minLen=10"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
}
type User struct {
BaseModel
Name string `json:"name,omitempty" gorm:"unique;not null" validate:"minLen=5;alpha"`
Role *Role `json:"role,omitempty" gormy:"edge=one"`
RoleID string `json:"roleId,omitempty"`
}
type Role struct {
BaseModel
Name string `json:"name,omitempty" gorm:"unique;not null" validate:"minLen=5;alpha" gormy:"default"`
DeniedActions string `json:"deniedActions,omitempty" gorm:"unique"`
DeniedFields string `json:"deniedFields,omitempty" gorm:"serializer:json"`
Users []User `json:"users,omitempty" gormy:"edge=many"`
}
func TestStruct(T *testing.T) {
err := validator.Struct(
&User{
Name: "Oussama",
Role: &Role{
Name: "admin",
},
},
)
if err != nil {
T.Error(err)
}
}