-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_test.go
More file actions
85 lines (70 loc) · 1.79 KB
/
logger_test.go
File metadata and controls
85 lines (70 loc) · 1.79 KB
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
package node
import (
"bytes"
"encoding/json"
"testing"
"github.com/AutoRoute/node/internal"
"github.com/AutoRoute/node/types"
)
func TestLogBloomFilter(t *testing.T) {
buf := bytes.Buffer{}
lgr := NewLogger(&buf)
a := types.NodeAddress("1")
bloomMap1 := internal.NewBloomReachabilityMap()
bloomMap1.AddEntry(a)
err := lgr.LogBloomFilter(bloomMap1)
if err != nil {
t.Fatal(err)
}
var bloomMap2 internal.BloomReachabilityMap
dec := json.NewDecoder(&buf)
err = dec.Decode(&bloomMap2.Conglomerate)
if err != nil {
t.Fatal(err)
}
if !(bloomMap2.IsReachable(a)) {
t.Fatal("Expected %s to be reachable in %v", a, bloomMap2)
}
}
func TestLogRoutingDecision(t *testing.T) {
buf := bytes.Buffer{}
lgr := NewLogger(&buf)
dest := types.NodeAddress("destination")
next := types.NodeAddress("next_hop")
packet_size := 10
packet_hash := types.PacketHash("packet_hash")
amt := int64(7)
err := lgr.LogRoutingDecision(dest, next, packet_size, amt, packet_hash)
if err != nil {
t.Fatal(err)
}
var rd routingDecision
dec := json.NewDecoder(&buf)
err = dec.Decode(&rd)
if err != nil {
t.Fatal(err)
}
if rd.Dest != dest || rd.Next != next ||
rd.PacketSize != packet_size || rd.Amt != amt ||
rd.PacketHash != packet_hash {
t.Fatal("Unexpected log entry", rd.Dest, rd.Next, rd.PacketSize, rd.Amt)
}
}
func TestLogPacketReceipt(t *testing.T) {
buf := bytes.Buffer{}
lgr := NewLogger(&buf)
packet_hash_in := types.PacketHash("packet_hash")
err := lgr.LogPacketReceipt(packet_hash_in)
if err != nil {
t.Fatal(err)
}
var packet_hash_out types.PacketHash
dec := json.NewDecoder(&buf)
err = dec.Decode(&packet_hash_out)
if err != nil {
t.Fatal(err)
}
if packet_hash_in != packet_hash_out {
t.Fatalf("Unexpected packet hash: %v != %v", packet_hash_in, packet_hash_out)
}
}