-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.go
48 lines (39 loc) · 1.05 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package libgorion
import (
"errors"
"testing"
)
func TestValidWorkers(t *testing.T) {
validCases := []string{"user", "сотрудник"}
for _, test := range validCases {
if err := validationWorker(test); err != nil {
t.Errorf("regexp don't match: (%v)", err)
}
}
}
func TestInvalidWorkers(t *testing.T) {
invalidCases := []string{"a", "123456"}
for _, test := range invalidCases {
err := validationWorker(test)
if err == errors.New("invalid worker. allowed only letters") {
t.Errorf("regexp don't match: (%v)", err)
}
}
}
func TestValidDate(t *testing.T) {
validCases := []string{"02.12.2007", "02-12-2007"}
for _, test := range validCases {
if err := validationDate(test); err != nil {
t.Errorf("regexp don't match: (%v)", err)
}
}
}
func TestInvalidDate(t *testing.T) {
invalidCases := []string{"02/12/2007", "f", "123456"}
for _, test := range invalidCases {
err = validationDate(test)
if err == errors.New("invalid date. corrects format: DD.MM.YYYY or DD-MM-YYYY") {
t.Errorf("regexp don't match: (%v)", err)
}
}
}