generated from OtusGolang/home_work
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator_test.go
60 lines (51 loc) · 1.05 KB
/
validator_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package hw09structvalidator
import (
"encoding/json"
"fmt"
"testing"
)
type UserRole string
// Test the function on different structures and other types.
type (
User struct {
ID string `json:"id" validate:"len:36"`
Name string
Age int `validate:"min:18|max:50"`
Email string `validate:"regexp:^\\w+@\\w+\\.\\w+$"`
Role UserRole `validate:"in:admin,stuff"`
Phones []string `validate:"len:11"`
meta json.RawMessage //nolint:unused
}
App struct {
Version string `validate:"len:5"`
}
Token struct {
Header []byte
Payload []byte
Signature []byte
}
Response struct {
Code int `validate:"in:200,404,500"`
Body string `json:"omitempty"`
}
)
func TestValidate(t *testing.T) {
tests := []struct {
in interface{}
expectedErr error
}{
{
// Place your code here.
},
// ...
// Place your code here.
}
for i, tt := range tests {
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
tt := tt
t.Parallel()
// Place your code here.
_ = tt
})
}
}