-
Notifications
You must be signed in to change notification settings - Fork 3
/
or_test.go
80 lines (74 loc) · 1.33 KB
/
or_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
package validator
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestOR_ValidateValue_Successfully(t *testing.T) {
ctx := context.Background()
type args struct {
rules []Rule
value any
}
tests := []struct {
name string
args args
}{
{
name: "ip or mac rules for ip value",
args: args{
rules: []Rule{
NewIP(),
NewMAC(),
},
value: "127.0.0.1",
},
},
{
name: "ip or mac rules for mac value",
args: args{
rules: []Rule{
NewIP(),
NewMAC(),
},
value: "00:1b:63:84:45:e6",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := NewOR("Value is not in ip or mac format.", tt.args.rules...)
err := o.ValidateValue(ctx, tt.args.value)
require.NoError(t, err)
})
}
}
func TestOR_ValidateValue_Failure(t *testing.T) {
ctx := context.Background()
type args struct {
rules []Rule
value any
}
tests := []struct {
name string
args args
}{
{
name: "ip or mac rules for invalid value",
args: args{
rules: []Rule{
NewIP(),
NewMAC(),
},
value: "hello world",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := NewOR("Value is not in ip or mac format.", tt.args.rules...)
err := o.ValidateValue(ctx, tt.args.value)
require.Error(t, err)
})
}
}