Commit 5423a008 authored by Jeromy's avatar Jeromy

create test node and make first ipns test pass

parent 0c7ff7b0
......@@ -6,6 +6,7 @@ import (
"testing"
fstest "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
func randBytes(size int) []byte {
......@@ -15,7 +16,12 @@ func randBytes(size int) []byte {
}
func TestIpnsBasicIO(t *testing.T) {
fs, err := NewIpns(nil, "")
localnode, err := testutil.NewMockNode()
if err != nil {
t.Fatal(err)
}
fs, err := NewIpns(localnode, "")
if err != nil {
t.Fatal(err)
}
......@@ -59,4 +65,5 @@ func TestIpnsBasicIO(t *testing.T) {
}
fi.Close()
}
package testutil
import (
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/sync"
bs "github.com/jbenet/go-ipfs/blockservice"
core "github.com/jbenet/go-ipfs/core"
ci "github.com/jbenet/go-ipfs/crypto"
mdag "github.com/jbenet/go-ipfs/merkledag"
nsys "github.com/jbenet/go-ipfs/namesys"
"github.com/jbenet/go-ipfs/peer"
mdht "github.com/jbenet/go-ipfs/routing/mock"
)
var _ = core.IpfsNode{}
func NewMockNode() (*core.IpfsNode, error) {
nd := new(core.IpfsNode)
//Generate Identity
nd.Identity = &peer.Peer{ID: []byte("TESTING")}
pk, sk, err := ci.GenerateKeyPair(ci.RSA, 1024)
if err != nil {
return nil, err
}
nd.Identity.PrivKey = pk
nd.Identity.PubKey = sk
// Temp Datastore
dstore := ds.NewMapDatastore()
nd.Datastore = syncds.MutexWrap(dstore)
// Routing
dht := mdht.NewMockRouter(nd.Identity, nd.Datastore)
// Bitswap
//??
bserv, err := bs.NewBlockService(nd.Datastore, nil)
if err != nil {
return nil, err
}
dserv := &mdag.DAGService{bserv}
// Namespace resolver
nd.Namesys = nsys.NewMasterResolver(dht, dserv)
return nd, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment