-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnotexists_test.go
71 lines (64 loc) · 1.57 KB
/
notexists_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
61
62
63
64
65
66
67
68
69
70
71
package govalidator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_NotExists(t *testing.T) {
tests := []struct {
name string
field string
value any
table string
column string
isPassed bool
msg string
expectedMsg string
}{
{
name: "test username of joe doesn't exist in defined users table",
field: "username",
value: "joe",
table: "users",
column: "username",
isPassed: true,
msg: "",
expectedMsg: "",
},
{
name: "test username of reza won't pass validation because it exists in defined users table",
field: "username",
value: "reza",
table: "users",
column: "username",
isPassed: false,
msg: "",
expectedMsg: "username already exists",
},
{
name: "test username of reza won't pass validation because it exists in defined users table",
field: "username",
value: "reza",
table: "users",
column: "username",
isPassed: false,
msg: "username `reza` already exists",
expectedMsg: "username `reza` already exists",
},
}
for _, test := range tests {
v := New().
WithRepo(repo{})
v.NotExists(test.value, test.table, test.column, test.field, test.msg)
assert.Equal(t, test.isPassed, v.IsPassed())
if v.IsFailed() {
assert.Equalf(
t,
test.expectedMsg,
v.Errors()[test.field],
"test case %q failed: expected: %s, got: %s",
test.expectedMsg,
v.Errors()[test.field],
)
}
}
}