-
Notifications
You must be signed in to change notification settings - Fork 1
/
peerlist_test.go
72 lines (63 loc) · 1.81 KB
/
peerlist_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
package wgconf_test
import (
"sort"
"strings"
"testing"
"github.com/gentlemanautomaton/wgconf"
)
func TestPeerListNetDev(t *testing.T) {
peers := selectTestPeers(tests, "Typical")
expected := `# T1 (test.typical.one)
[WireGuardPeer]
PublicKey=aPxGwq8zERHQ3Q1cOZFdJ+cvJX5Ka4mLN38AyYKYF10=
AllowedIPs=192.168.0.1/32
# T2 (two)
[WireGuardPeer]
PublicKey=aPxGwq8zERHQ3Q1cOZFdJ+cvJX5Ka4mLN38AyYKYF10=
AllowedIPs=192.168.1.1/30
# T3 (thrice)
[WireGuardPeer]
PublicKey=aPxGwq8zERHQ3Q1cOZFdJ+cvJX5Ka4mLN38AyYKYF10=
AllowedIPs=10.0.0.1/22,192.168.0.254/32,::/0
# T4 (four)
[WireGuardPeer]
PublicKey=aPxGwq8zERHQ3Q1cOZFdJ+cvJX5Ka4mLN38AyYKYF10=
AllowedIPs=192.168.0.253/32,10.0.0.11/22`
if diff := multilineDiff(peers.NetDev(), expected); diff != "" {
t.Fatalf("unexpected PeerList.NetDev() output (-want +got):\n%s", diff)
}
}
func selectTestPeers(list []PeerTest, prefix string) (peers wgconf.PeerList) {
for _, tt := range tests {
if strings.HasPrefix(tt.Name, prefix) {
peers = append(peers, tt.Peer)
}
}
return peers
}
func TestPeerListSortTypical(t *testing.T) {
peers := selectTestPeers(tests, "Typical")
sort.Sort(peers)
expected := "T3,T1,T4,T2"
var values []string
for _, peer := range peers {
values = append(values, peer.Name)
}
actual := strings.Join(values, ",")
if diff := multilineDiff(actual, expected); diff != "" {
t.Fatalf("unexpected PeerList.NetDev() output (-want +got):\n%s", diff)
}
}
func TestPeerListSortCompare(t *testing.T) {
peers := selectTestPeers(tests, "Compare")
sort.Sort(peers)
expected := "C6,C7,C8,C4,C5,C2,C3,C1"
var values []string
for _, peer := range peers {
values = append(values, peer.Name)
}
actual := strings.Join(values, ",")
if diff := multilineDiff(actual, expected); diff != "" {
t.Fatalf("unexpected PeerList.NetDev() output (-want +got):\n%s", diff)
}
}