storj/pkg/kademlia/replacement_cache_test.go
Jennifer Li Johnson 91bf6e19e8
Routing Table Replacement Cache (#229)
* creating replacement cache

* wip

* wip

* rewrites replacement cache

* replacement cache tests

* update and remove node tests

* check if dropped node got added to replacement cache from add node method

* wip

* wip

* making changes based on pr
2018-08-17 15:11:46 -04:00

31 lines
1.0 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information
package kademlia
import (
"testing"
"github.com/stretchr/testify/assert"
proto "storj.io/storj/protos/overlay"
)
func TestAddToReplacementCache(t *testing.T) {
rt := createRT([]byte{244, 255})
kadBucketID := []byte{255, 255}
node1 := mockNode(string([]byte{233, 255}))
rt.addToReplacementCache(kadBucketID, node1)
assert.Equal(t, []*proto.Node{node1}, rt.replacementCache[string(kadBucketID)])
kadBucketID2 := []byte{127, 255}
node2 := mockNode(string([]byte{100, 255}))
node3 := mockNode(string([]byte{90, 255}))
node4 := mockNode(string([]byte{80, 255}))
rt.addToReplacementCache(kadBucketID2, node2)
rt.addToReplacementCache(kadBucketID2, node3)
assert.Equal(t, []*proto.Node{node1}, rt.replacementCache[string(kadBucketID)])
assert.Equal(t, []*proto.Node{node2, node3}, rt.replacementCache[string(kadBucketID2)])
rt.addToReplacementCache(kadBucketID2, node4)
assert.Equal(t, []*proto.Node{node3, node4}, rt.replacementCache[string(kadBucketID2)])
}