-
Notifications
You must be signed in to change notification settings - Fork 4
/
mac_test.go
86 lines (79 loc) · 1.93 KB
/
mac_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package govalidator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_MAC(t *testing.T) {
tests := []struct {
name string
field string
value string
isPassed bool
message string
expectedMsg string
}{
{
name: "test a correct mac address string value will pass validation",
field: "mac",
value: "00-B0-D0-63-C2-26",
isPassed: true,
message: "",
expectedMsg: "",
},
{
name: "test a correct mac address string value will pass validation",
field: "mac",
value: "00:B0:D0:63:C2:26",
isPassed: true,
message: "",
expectedMsg: "",
},
{
name: "test a wrong string value will fail mac address validation",
field: "mac_address",
value: "22-aha-sh1-13-b12",
isPassed: false,
message: "",
expectedMsg: "mac_address is not valid",
},
{
name: "test a wrong string value will fail mac address validation",
field: "mac",
value: "12-$13-me-%3$-e23",
isPassed: false,
message: "",
expectedMsg: "mac is not valid",
},
{
name: "test an empty string value will fail mac validation",
field: "mac",
value: "",
isPassed: false,
message: "mac is not valid",
expectedMsg: "mac is not valid",
},
{
name: "test an empty space string value will fail mac validation",
field: "mac_address",
value: " ",
isPassed: false,
message: "mac_address is not valid",
expectedMsg: "mac_address is not valid",
},
}
for _, test := range tests {
v := New()
v.MAC(test.value, test.field, test.message)
assert.Equal(t, test.isPassed, v.IsPassed())
if !test.isPassed {
assert.Equalf(
t,
test.expectedMsg,
v.Errors()[test.field],
"test case %q failed, expected: %s, got: %s",
test.expectedMsg,
v.Errors()[test.field],
)
}
}
}