storj/pkg/kademlia/test_utils.go
Dennis Coyle a5ff5016c9
pkg/kademlia tests and restructuring (#97)
* port changes

* Merge remote-tracking branch 'upstream/master'

* Merge remote-tracking branch 'upstream/master'

* Merge remote-tracking branch 'upstream/master'

* files created

* Merge remote-tracking branch 'upstream/master' into coyle/kad-tests

* wip

* Merge remote-tracking branch 'upstream/master' into coyle/kad-tests

* wip

* remove bkad dependencie from tests

* wip

* wip

* wip

* wip

* wip

* updated coyle/kademlia

* wip

* cleanup

* ports

* overlay upgraded

* linter fixes

* piecestore kademlia newID

* add changes from kad demo

* PR comments addresses

* go func

* force travis build

* fixed merge conflicts

* fixed merge conflicts

* Merge branch 'coyle/kad-tests' of https://github.com/coyle/storj into coyle/kad-tests

* linter issues

* linting issues

* fixed merge conflicts

* linter is stupid
2018-06-22 09:33:57 -04:00

58 lines
1.6 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package kademlia
import (
"context"
"storj.io/storj/pkg/dht"
proto "storj.io/storj/protos/overlay"
)
// NewMockKademlia returns a newly intialized MockKademlia struct
func NewMockKademlia() *MockKademlia {
return &MockKademlia{}
}
// MockKademlia is a mock implementation of the DHT interface used solely for testing
type MockKademlia struct {
RoutingTable dht.RoutingTable
Nodes []*proto.Node
}
// GetNodes increments the GetNodesCalled field on MockKademlia
// returns the Nodes field on MockKademlia
func (k *MockKademlia) GetNodes(ctx context.Context, start string, limit int) ([]*proto.Node, error) {
return k.Nodes, nil
}
// GetRoutingTable increments the GetRoutingTableCalled field on MockKademlia
//
// returns the RoutingTable field on MockKademlia
func (k *MockKademlia) GetRoutingTable(ctx context.Context) (dht.RoutingTable, error) {
return k.RoutingTable, nil
}
// Bootstrap increments the BootstrapCalled field on MockKademlia
func (k *MockKademlia) Bootstrap(ctx context.Context) error {
return nil
}
// Ping increments the PingCalled field on MockKademlia
func (k *MockKademlia) Ping(ctx context.Context, node proto.Node) (proto.Node, error) {
return node, nil
}
// FindNode increments the FindNodeCalled field on MockKademlia
//
// returns the local kademlia node
func (k *MockKademlia) FindNode(ctx context.Context, ID dht.NodeID) (proto.Node, error) {
return k.RoutingTable.Local(), nil
}
// Disconnect increments the DisconnectCalled field on MockKademlia
func (k *MockKademlia) Disconnect() error {
return nil
}