-
Notifications
You must be signed in to change notification settings - Fork 0
/
declaration_test.go
62 lines (56 loc) · 2.02 KB
/
declaration_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
package vintage
import (
"net"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestBackendDeclaration(t *testing.T) {
b := NewBackend("F_example", BackendDefault())
if diff := cmp.Diff(b.Backend(RequestIdentity{}), "F_example"); diff != "" {
t.Errorf("Value unmatch, diff=%s", diff)
}
}
func TestAclDeclaration(t *testing.T) {
tests := []struct {
acl *Acl
expect string
}{
{acl: NewAcl("example", AclEntry("192.168.0.0/32", false)), expect: "192.168.0.0"},
{acl: NewAcl("example", AclEntry("192.168.0.0/32", true)), expect: "192.168.0.1"},
{acl: NewAcl("example", AclEntry("192.168.0.0/24", false)), expect: "192.168.0.255"},
{acl: NewAcl("example", AclEntry("192.168.0.0/24", true)), expect: "192.168.1.0"},
}
for i, tt := range tests {
if diff := cmp.Diff(tt.acl.Match(net.ParseIP(tt.expect)), true); diff != "" {
t.Errorf("[%d] Value unmatch, diff=%s", i, diff)
}
}
}
func TestTableDeclaration(t *testing.T) {
st := NewTable("example", "STRING", TableItem("foo", "bar"))
if diff := cmp.Diff(st.Items["foo"], "bar"); diff != "" {
t.Errorf("String Table: Value unmatch, diff=%s", diff)
}
it := NewTable("example", "INTEGER", TableItem("foo", 100))
if diff := cmp.Diff(it.Items["foo"], 100); diff != "" {
t.Errorf("Integer Table: Value unmatch, diff=%s", diff)
}
ft := NewTable("example", "FLOAT", TableItem("foo", 100.001))
if diff := cmp.Diff(ft.Items["foo"], 100.001); diff != "" {
t.Errorf("Float Table: Value unmatch, diff=%s", diff)
}
bt := NewTable("example", "BOOL", TableItem("foo", true))
if diff := cmp.Diff(bt.Items["foo"], true); diff != "" {
t.Errorf("Bool Table: Value unmatch, diff=%s", diff)
}
rt := NewTable("example", "RTIME", TableItem("foo", time.Second))
if diff := cmp.Diff(rt.Items["foo"], time.Second); diff != "" {
t.Errorf("RTime Table: Value unmatch, diff=%s", diff)
}
now := time.Now()
tt := NewTable("example", "TIME", TableItem("foo", now))
if diff := cmp.Diff(tt.Items["foo"], now); diff != "" {
t.Errorf("Time Table: Value unmatch, diff=%s", diff)
}
}