-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration_test.go
61 lines (56 loc) · 1.59 KB
/
configuration_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
package p2p
import (
"fmt"
"reflect"
"testing"
"time"
)
func TestConfiguration_Sanitize(t *testing.T) {
tmp := DefaultP2PConfiguration()
c := &tmp
c.MaxIncoming = 50
c.MaxPeers = 45
c.Sanitize()
if c.MaxIncoming > c.MaxPeers {
t.Errorf("allowing more incoming peers than possible peers. incoming = %d, max = %d", c.MaxIncoming, c.MaxPeers)
}
}
func TestConfiguration_Check(t *testing.T) {
if err := DefaultP2PConfiguration().Check(); err != nil {
t.Errorf("DefaultConfiguration().Check() reported error = %v", err)
}
tests := []struct {
name string
v interface{}
}{
{"ListenPort", ""},
{"ListenPort", "abc"},
{"ListenPort", ":123"},
{"ListenPort", "123abc"},
{"PeerShareAmount", uint(0)},
{"RoundTime", time.Duration(0)},
{"TargetPeers", uint(0)},
{"Fanout", uint(0)},
{"HandshakeTimeout", time.Duration(0)},
{"DialTimeout", time.Duration(0)},
{"ReadDeadline", time.Duration(0)},
{"WriteDeadline", time.Duration(0)},
{"ProtocolVersion", uint16(0)},
{"ProtocolVersion", uint16(8)},
{"ProtocolVersion", uint16(12)},
{"ProtocolVersionMinimum", uint16(12)},
{"ChannelCapacity", uint(0)},
{"Special", "abc"}, // parseSpecial has its own unit tests, only check that it's checked
}
for i, tt := range tests {
t.Run(fmt.Sprintf("%d-%s", i, tt.name), func(t *testing.T) {
con := DefaultP2PConfiguration()
r := reflect.ValueOf(&con)
field := reflect.Indirect(r).FieldByName(tt.name)
field.Set(reflect.ValueOf(tt.v))
if err := con.Check(); err == nil {
t.Errorf("Configuration.Check() error = %v, wantErrField = %s", err, tt.name)
}
})
}
}