Resolve circular dependency by porting testutil functions over

This commit is contained in:
Lars Gierth 2016-04-15 22:56:55 -07:00
parent 0cf66c98e5
commit ad26c6b105
3 changed files with 28 additions and 2 deletions

View File

@ -7,7 +7,7 @@ import (
"time"
peer "github.com/ipfs/go-libp2p-peer"
testutil "github.com/ipfs/go-libp2p/testutil"
testutil "github.com/ipfs/go-libp2p-peer/test"
)
func TestLatencyEWMAFun(t *testing.T) {

View File

@ -9,7 +9,7 @@ import (
u "github.com/ipfs/go-ipfs-util"
ic "github.com/ipfs/go-libp2p-crypto"
. "github.com/ipfs/go-libp2p-peer"
tu "github.com/ipfs/go-libp2p/testutil"
tu "github.com/ipfs/go-libp2p-peer/test"
b58 "github.com/jbenet/go-base58"
)

26
test/utils.go Normal file
View File

@ -0,0 +1,26 @@
package testutil
import (
"io"
u "github.com/ipfs/go-ipfs-util"
ci "github.com/ipfs/go-libp2p-crypto"
peer "github.com/ipfs/go-libp2p-peer"
)
func RandPeerID() (peer.ID, error) {
buf := make([]byte, 16)
if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil {
return "", err
}
h := u.Hash(buf)
return peer.ID(h), nil
}
func RandTestKeyPair(bits int) (ci.PrivKey, ci.PubKey, error) {
return ci.GenerateKeyPairWithReader(ci.RSA, bits, u.NewTimeSeededRand())
}
func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) {
return ci.GenerateKeyPairWithReader(ci.RSA, 512, u.NewSeededRand(seed))
}