small test

This commit is contained in:
Alex Grintsvayg 2018-06-19 14:06:35 -04:00
parent 5e346cc21a
commit 47a732688d
2 changed files with 21 additions and 2 deletions

View file

@ -258,13 +258,17 @@ type routingTable struct {
func newRoutingTable(id bits.Bitmap) *routingTable {
var rt routingTable
rt.id = id
rt.reset()
return &rt
}
func (rt *routingTable) reset() {
for i := range rt.buckets {
rt.buckets[i] = bucket{
peers: make([]peer, 0, bucketSize),
lock: &sync.RWMutex{},
}
}
return &rt
}
func (rt *routingTable) BucketInfo() string {
@ -415,6 +419,7 @@ func (rt *routingTable) UnmarshalJSON(b []byte) error {
if err != nil {
return errors.Prefix("decoding ID", err)
}
rt.reset()
for _, s := range data.Contacts {
parts := strings.Split(s, rtContactSep)

View file

@ -195,6 +195,20 @@ func TestRoutingTable_Save(t *testing.T) {
goldie.Assert(t, t.Name(), data)
}
func TestRoutingTable_Load(t *testing.T) {
func TestRoutingTable_Load_ID(t *testing.T) {
id := "1c8aff71b99462464d9eeac639595ab99664be3482cb91a29d87467515c7d9158fe72aa1f1582dab07d8f8b5db277f41"
data := []byte(`{"id": "` + id + `","contacts": []}`)
rt := routingTable{}
err := json.Unmarshal(data, &rt)
if err != nil {
t.Error(err)
}
if rt.id.Hex() != id {
t.Error("id mismatch")
}
}
func TestRoutingTable_Load_Contacts(t *testing.T) {
t.Skip("TODO")
}