-
Notifications
You must be signed in to change notification settings - Fork 5
/
inireader_test.go
106 lines (93 loc) · 3.4 KB
/
inireader_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"github.com/ipcjk/ixgen/inireader"
"github.com/ipcjk/ixgen/ixtypes"
"testing"
)
func TestParsePeerFunction(t *testing.T) {
Line := "196922 ipv4=1 ipv6=0 active=1 prefix_filter=1 local_pref=910 group6=0 group=0 peer_group6=mygroup6 peer_group=mygroup4 password4=session4 password6=session6"
Peer := inireader.ParsePeerLine(Line, 0)
if Peer.ASN != "196922" {
t.Error("Peer ASN is different than expected")
}
if !Peer.PrefixFilterEnabled {
t.Error("Peer Prefix Filter is different than expected")
}
if Peer.Ipv6Enabled {
t.Error("Peer Ipv6 value is different than expected")
}
if !Peer.Ipv4Enabled {
t.Error("Peer Ipv4 value is different than expected")
}
if !Peer.Active {
t.Error("Peer Active value is different than expected")
}
if Peer.GroupEnabled {
t.Error("Peer Group enabled/disabled is different than expected")
}
if Peer.Group6Enabled {
t.Error("Peer Group6 enabled/disabled is different than expected")
}
if Peer.Group != "mygroup4" {
t.Error("Peer Group string is different than expected")
}
if Peer.Group6 != "mygroup6" {
t.Error("Peer Group6 string is different than expected")
}
if Peer.Password4 != "session4" {
t.Error("Peer Password string is different than expected")
}
if Peer.Password6 != "session6" {
t.Error("Peer Password string is different than expected")
}
}
func TestExchangeOption(t *testing.T) {
/* Init test object */
var ixConfig = make(ixtypes.ExchangeOptions)
ixConfig["testIX"] = make(map[string]ixtypes.ExchangeOption, 10)
inireader.ParseOptionLine("ixid=12222", ixConfig, "testIX")
inireader.ParseOptionLine("routeserver=1", ixConfig, "testIX")
inireader.ParseOptionLine("routeserver_group=IX", ixConfig, "testIX")
inireader.ParseOptionLine("routeserver_group6=IX6", ixConfig, "testIX")
inireader.ParseOptionLine("peer_group=peer", ixConfig, "testIX")
inireader.ParseOptionLine("peer_group6=peer6", ixConfig, "testIX")
inireader.ParseOptionLine("wildcard=1", ixConfig, "testIX")
inireader.ParseOptionLine("importpolicy=foo1", ixConfig, "testIX")
inireader.ParseOptionLine("exportpolicy=foo2", ixConfig, "testIX")
inireader.ParseOptionLine("routeserver_prefixes=10000", ixConfig, "testIX")
inireader.ParseOptionLine("routeserver_prefixes6=400", ixConfig, "testIX")
inireader.ParseOptionLine("rs_asn=6695", ixConfig, "testIX")
inireader.ParseOptionLine("wildcard_prefix_filter=1", ixConfig, "testIX")
/* Check that we covered all cases from inireader */
for k := range inireader.PossibleOptions {
_, ok := ixConfig["testIX"][k]
if !ok {
t.Errorf("option %s not readable ", k)
}
}
/* Check static for every case we give above */
if ixConfig["testIX"]["routeserver"] != "1" {
t.Error("Routeserver option is wrong")
}
if ixConfig["testIX"]["routeserver_group"] != "IX" {
t.Error("Routeserver Group option is wrong")
}
if ixConfig["testIX"]["routeserver_group6"] != "IX6" {
t.Error("Routeserver Group6 option is wrong")
}
if ixConfig["testIX"]["peer_group"] != "peer" {
t.Error("Peer Group option is wrong")
}
if ixConfig["testIX"]["peer_group6"] != "peer6" {
t.Error("Peer Group6 option is wrong")
}
if ixConfig["testIX"]["wildcard"] != "1" {
t.Error("Wildcard option is wrong")
}
if ixConfig["testIX"]["rs_asn"] != "6695" {
t.Error("Route-Server ASN number is wrong")
}
if ixConfig["testIX"]["wildcard_prefix_filter"] != "1" {
t.Error("Prefix filter options for wildcards peers is not set")
}
}