mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
coreapi: don't touch IpfsNode in tests
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
d06cf14f8e
commit
ac529e75ce
@ -14,7 +14,7 @@ import (
|
||||
|
||||
func TestBlockPut(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -31,7 +31,7 @@ func TestBlockPut(t *testing.T) {
|
||||
|
||||
func TestBlockPutFormat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -48,7 +48,7 @@ func TestBlockPutFormat(t *testing.T) {
|
||||
|
||||
func TestBlockPutHash(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -65,7 +65,7 @@ func TestBlockPutHash(t *testing.T) {
|
||||
|
||||
func TestBlockGet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -105,7 +105,7 @@ func TestBlockGet(t *testing.T) {
|
||||
|
||||
func TestBlockRm(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -158,7 +158,7 @@ func TestBlockRm(t *testing.T) {
|
||||
|
||||
func TestBlockStat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -30,6 +30,9 @@ type dagBatch struct {
|
||||
// Returns the path of the inserted data.
|
||||
func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (coreiface.ResolvedPath, error) {
|
||||
nd, err := getNode(src, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = api.dag.Add(ctx, nd)
|
||||
if err != nil {
|
||||
|
||||
@ -24,7 +24,7 @@ var (
|
||||
|
||||
func TestPut(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -41,7 +41,7 @@ func TestPut(t *testing.T) {
|
||||
|
||||
func TestPutWithHash(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -58,7 +58,7 @@ func TestPutWithHash(t *testing.T) {
|
||||
|
||||
func TestPath(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -90,7 +90,7 @@ func TestPath(t *testing.T) {
|
||||
|
||||
func TestTree(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -119,7 +119,7 @@ func TestTree(t *testing.T) {
|
||||
|
||||
func TestBatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -3,24 +3,24 @@ package coreapi_test
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
blocks "gx/ipfs/QmWoXtvgC8inqFkAATB7cp2Dax7XBi9VDvSg9RCCZufmRk/go-block-format"
|
||||
peer "gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
|
||||
)
|
||||
|
||||
func TestDhtFindPeer(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
nds, apis, err := makeAPISwarm(ctx, true, 5)
|
||||
apis, err := makeAPISwarm(ctx, true, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pi, err := apis[2].Dht().FindPeer(ctx, peer.ID(nds[0].Identity))
|
||||
self0, err := apis[0].Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pi, err := apis[2].Dht().FindPeer(ctx, self0.ID())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -29,7 +29,12 @@ func TestDhtFindPeer(t *testing.T) {
|
||||
t.Errorf("got unexpected address from FindPeer: %s", pi.Addrs[0].String())
|
||||
}
|
||||
|
||||
pi, err = apis[1].Dht().FindPeer(ctx, peer.ID(nds[2].Identity))
|
||||
self2, err := apis[2].Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pi, err = apis[1].Dht().FindPeer(ctx, self2.ID())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -41,7 +46,7 @@ func TestDhtFindPeer(t *testing.T) {
|
||||
|
||||
func TestDhtFindProviders(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
nds, apis, err := makeAPISwarm(ctx, true, 5)
|
||||
apis, err := makeAPISwarm(ctx, true, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -58,27 +63,34 @@ func TestDhtFindProviders(t *testing.T) {
|
||||
|
||||
provider := <-out
|
||||
|
||||
if provider.ID.String() != nds[0].Identity.String() {
|
||||
t.Errorf("got wrong provider: %s != %s", provider.ID.String(), nds[0].Identity.String())
|
||||
self0, err := apis[0].Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if provider.ID.String() != self0.ID().String() {
|
||||
t.Errorf("got wrong provider: %s != %s", provider.ID.String(), self0.ID().String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDhtProvide(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
nds, apis, err := makeAPISwarm(ctx, true, 5)
|
||||
apis, err := makeAPISwarm(ctx, true, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// TODO: replace once there is local add on unixfs or somewhere
|
||||
data, err := ioutil.ReadAll(&io.LimitedReader{R: rnd, N: 4092})
|
||||
off0, err := apis[0].WithOptions(options.Api.Offline(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b := blocks.NewBlock(data)
|
||||
nds[0].Blockstore.Put(b)
|
||||
p := iface.IpfsPath(b.Cid())
|
||||
s, err := off0.Block().Put(ctx, &io.LimitedReader{R: rnd, N: 4092})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := s.Path()
|
||||
|
||||
out, err := apis[2].Dht().FindProviders(ctx, p, options.Dht.NumProviders(1))
|
||||
if err != nil {
|
||||
@ -87,8 +99,13 @@ func TestDhtProvide(t *testing.T) {
|
||||
|
||||
provider := <-out
|
||||
|
||||
self0, err := apis[0].Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if provider.ID.String() != "<peer.ID >" {
|
||||
t.Errorf("got wrong provider: %s != %s", provider.ID.String(), nds[0].Identity.String())
|
||||
t.Errorf("got wrong provider: %s != %s", provider.ID.String(), self0.ID().String())
|
||||
}
|
||||
|
||||
err = apis[0].Dht().Provide(ctx, p)
|
||||
@ -103,7 +120,7 @@ func TestDhtProvide(t *testing.T) {
|
||||
|
||||
provider = <-out
|
||||
|
||||
if provider.ID.String() != nds[0].Identity.String() {
|
||||
t.Errorf("got wrong provider: %s != %s", provider.ID.String(), nds[0].Identity.String())
|
||||
if provider.ID.String() != self0.ID().String() {
|
||||
t.Errorf("got wrong provider: %s != %s", provider.ID.String(), self0.ID().String())
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestListSelf(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -38,7 +38,7 @@ func TestListSelf(t *testing.T) {
|
||||
|
||||
func TestRenameSelf(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -65,7 +65,7 @@ func TestRenameSelf(t *testing.T) {
|
||||
|
||||
func TestRemoveSelf(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
@ -83,7 +83,7 @@ func TestRemoveSelf(t *testing.T) {
|
||||
|
||||
func TestGenerate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -105,7 +105,7 @@ func TestGenerate(t *testing.T) {
|
||||
|
||||
func TestGenerateSize(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -129,7 +129,7 @@ func TestGenerateType(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
t.Skip("disabled until libp2p/specs#111 is fixed")
|
||||
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -152,7 +152,7 @@ func TestGenerateType(t *testing.T) {
|
||||
|
||||
func TestGenerateExisting(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -184,7 +184,7 @@ func TestGenerateExisting(t *testing.T) {
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -229,7 +229,7 @@ func TestList(t *testing.T) {
|
||||
|
||||
func TestRename(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -257,7 +257,7 @@ func TestRename(t *testing.T) {
|
||||
|
||||
func TestRenameToSelf(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -280,7 +280,7 @@ func TestRenameToSelf(t *testing.T) {
|
||||
|
||||
func TestRenameToSelfForce(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -303,7 +303,7 @@ func TestRenameToSelfForce(t *testing.T) {
|
||||
|
||||
func TestRenameOverwriteNoForce(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -332,7 +332,7 @@ func TestRenameOverwriteNoForce(t *testing.T) {
|
||||
|
||||
func TestRenameOverwrite(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -370,7 +370,7 @@ func TestRenameOverwrite(t *testing.T) {
|
||||
|
||||
func TestRenameSameNameNoForce(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -398,7 +398,7 @@ func TestRenameSameNameNoForce(t *testing.T) {
|
||||
|
||||
func TestRenameSameName(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -426,7 +426,7 @@ func TestRenameSameName(t *testing.T) {
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -2,14 +2,13 @@ package coreapi_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"io"
|
||||
"math/rand"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
ipath "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
|
||||
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
@ -32,34 +31,37 @@ func appendPath(p coreiface.Path, sub string) coreiface.Path {
|
||||
|
||||
func TestPublishResolve(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
init := func() (*core.IpfsNode, coreiface.CoreAPI, coreiface.Path) {
|
||||
nds, apis, err := makeAPISwarm(ctx, true, 5)
|
||||
init := func() (coreiface.CoreAPI, coreiface.Path) {
|
||||
apis, err := makeAPISwarm(ctx, true, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return nil, nil, nil
|
||||
return nil, nil
|
||||
}
|
||||
n := nds[0]
|
||||
api := apis[0]
|
||||
|
||||
p, err := addTestObject(ctx, api)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return nil, nil, nil
|
||||
return nil, nil
|
||||
}
|
||||
return n, api, p
|
||||
return api, p
|
||||
}
|
||||
|
||||
run := func(t *testing.T, ropts []opt.NameResolveOption) {
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
n, api, p := init()
|
||||
api, p := init()
|
||||
e, err := api.Name().Publish(ctx, p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if e.Name() != n.Identity.Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", n.Identity.Pretty(), e.Name())
|
||||
self, err := api.Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if e.Name() != self.ID().Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", self.ID().Pretty(), e.Name())
|
||||
}
|
||||
|
||||
if e.Value().String() != p.String() {
|
||||
@ -69,7 +71,6 @@ func TestPublishResolve(t *testing.T) {
|
||||
resPath, err := api.Name().Resolve(ctx, e.Name(), ropts...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if resPath.String() != p.String() {
|
||||
@ -78,15 +79,19 @@ func TestPublishResolve(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("publishPath", func(t *testing.T) {
|
||||
n, api, p := init()
|
||||
api, p := init()
|
||||
e, err := api.Name().Publish(ctx, appendPath(p, "/test"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if e.Name() != n.Identity.Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", n.Identity.Pretty(), e.Name())
|
||||
self, err := api.Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if e.Name() != self.ID().Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", self.ID().Pretty(), e.Name())
|
||||
}
|
||||
|
||||
if e.Value().String() != p.String()+"/test" {
|
||||
@ -96,7 +101,6 @@ func TestPublishResolve(t *testing.T) {
|
||||
resPath, err := api.Name().Resolve(ctx, e.Name(), ropts...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if resPath.String() != p.String()+"/test" {
|
||||
@ -105,15 +109,19 @@ func TestPublishResolve(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("revolvePath", func(t *testing.T) {
|
||||
n, api, p := init()
|
||||
api, p := init()
|
||||
e, err := api.Name().Publish(ctx, p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if e.Name() != n.Identity.Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", n.Identity.Pretty(), e.Name())
|
||||
self, err := api.Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if e.Name() != self.ID().Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", self.ID().Pretty(), e.Name())
|
||||
}
|
||||
|
||||
if e.Value().String() != p.String() {
|
||||
@ -123,7 +131,6 @@ func TestPublishResolve(t *testing.T) {
|
||||
resPath, err := api.Name().Resolve(ctx, e.Name()+"/test", ropts...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if resPath.String() != p.String()+"/test" {
|
||||
@ -132,15 +139,19 @@ func TestPublishResolve(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("publishRevolvePath", func(t *testing.T) {
|
||||
n, api, p := init()
|
||||
api, p := init()
|
||||
e, err := api.Name().Publish(ctx, appendPath(p, "/a"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if e.Name() != n.Identity.Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", n.Identity.Pretty(), e.Name())
|
||||
self, err := api.Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if e.Name() != self.ID().Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", self.ID().Pretty(), e.Name())
|
||||
}
|
||||
|
||||
if e.Value().String() != p.String()+"/a" {
|
||||
@ -150,7 +161,6 @@ func TestPublishResolve(t *testing.T) {
|
||||
resPath, err := api.Name().Resolve(ctx, e.Name()+"/b", ropts...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if resPath.String() != p.String()+"/a/b" {
|
||||
@ -170,29 +180,25 @@ func TestPublishResolve(t *testing.T) {
|
||||
|
||||
func TestBasicPublishResolveKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, apis, err := makeAPISwarm(ctx, true, 5)
|
||||
apis, err := makeAPISwarm(ctx, true, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
api := apis[0]
|
||||
|
||||
k, err := api.Key().Generate(ctx, "foo")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
p, err := addTestObject(ctx, api)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
e, err := api.Name().Publish(ctx, p, opt.Name.Key(k.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if ipath.Join([]string{"/ipns", e.Name()}) != k.Path().String() {
|
||||
@ -206,7 +212,6 @@ func TestBasicPublishResolveKey(t *testing.T) {
|
||||
resPath, err := api.Name().Resolve(ctx, e.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if resPath.String() != p.String() {
|
||||
@ -218,27 +223,28 @@ func TestBasicPublishResolveTimeout(t *testing.T) {
|
||||
t.Skip("ValidTime doesn't appear to work at this time resolution")
|
||||
|
||||
ctx := context.Background()
|
||||
nds, apis, err := makeAPISwarm(ctx, true, 5)
|
||||
apis, err := makeAPISwarm(ctx, true, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
n := nds[0]
|
||||
api := apis[0]
|
||||
p, err := addTestObject(ctx, api)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
e, err := api.Name().Publish(ctx, p, opt.Name.ValidTime(time.Millisecond*100))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if e.Name() != n.Identity.Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", n.Identity.Pretty(), e.Name())
|
||||
self, err := api.Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if e.Name() != self.ID().Pretty() {
|
||||
t.Errorf("expected e.Name to equal '%s', got '%s'", self.ID().Pretty(), e.Name())
|
||||
}
|
||||
|
||||
if e.Value().String() != p.String() {
|
||||
@ -250,7 +256,6 @@ func TestBasicPublishResolveTimeout(t *testing.T) {
|
||||
_, err = api.Name().Resolve(ctx, e.Name())
|
||||
if err == nil {
|
||||
t.Fatal("Expected an error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -40,7 +40,7 @@ func TestNew(t *testing.T) {
|
||||
|
||||
func TestObjectPut(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -80,7 +80,7 @@ func TestObjectPut(t *testing.T) {
|
||||
|
||||
func TestObjectGet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -102,7 +102,7 @@ func TestObjectGet(t *testing.T) {
|
||||
|
||||
func TestObjectData(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -129,7 +129,7 @@ func TestObjectData(t *testing.T) {
|
||||
|
||||
func TestObjectLinks(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -164,7 +164,7 @@ func TestObjectLinks(t *testing.T) {
|
||||
|
||||
func TestObjectStat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -211,7 +211,7 @@ func TestObjectStat(t *testing.T) {
|
||||
|
||||
func TestObjectAddLink(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -251,7 +251,7 @@ func TestObjectAddLink(t *testing.T) {
|
||||
|
||||
func TestObjectAddLinkCreate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -299,7 +299,7 @@ func TestObjectAddLinkCreate(t *testing.T) {
|
||||
|
||||
func TestObjectRmLink(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -331,7 +331,7 @@ func TestObjectRmLink(t *testing.T) {
|
||||
|
||||
func TestObjectAddData(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -360,7 +360,7 @@ func TestObjectAddData(t *testing.T) {
|
||||
|
||||
func TestObjectSetData(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -389,7 +389,7 @@ func TestObjectSetData(t *testing.T) {
|
||||
|
||||
func TestDiffTest(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
func TestMutablePath(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -38,7 +38,7 @@ func TestMutablePath(t *testing.T) {
|
||||
|
||||
func TestPathRemainder(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -65,7 +65,7 @@ func TestPathRemainder(t *testing.T) {
|
||||
|
||||
func TestEmptyPathRemainder(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -96,7 +96,7 @@ func TestEmptyPathRemainder(t *testing.T) {
|
||||
|
||||
func TestInvalidPathRemainder(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -119,7 +119,7 @@ func TestInvalidPathRemainder(t *testing.T) {
|
||||
|
||||
func TestPathRoot(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestPinAdd(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -28,7 +28,7 @@ func TestPinAdd(t *testing.T) {
|
||||
|
||||
func TestPinSimple(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -77,7 +77,7 @@ func TestPinSimple(t *testing.T) {
|
||||
|
||||
func TestPinRecursive(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
nd, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -176,36 +176,39 @@ func TestPinRecursive(t *testing.T) {
|
||||
t.Errorf("unexpected verify result count: %d", n)
|
||||
}
|
||||
|
||||
err = nd.Blockstore.DeleteBlock(p0.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err = api.Pin().Verify(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n = 0
|
||||
for r := range res {
|
||||
if r.Ok() {
|
||||
t.Error("expected pin to not be ok")
|
||||
//TODO: figure out a way to test verify without touching IpfsNode
|
||||
/*
|
||||
err = api.Block().Rm(ctx, p0, opt.Block.Force(true))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(r.BadNodes()) != 1 {
|
||||
t.Fatalf("unexpected badNodes len")
|
||||
res, err = api.Pin().Verify(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n = 0
|
||||
for r := range res {
|
||||
if r.Ok() {
|
||||
t.Error("expected pin to not be ok")
|
||||
}
|
||||
|
||||
if len(r.BadNodes()) != 1 {
|
||||
t.Fatalf("unexpected badNodes len")
|
||||
}
|
||||
|
||||
if r.BadNodes()[0].Path().Cid().String() != p0.Cid().String() {
|
||||
t.Error("unexpected badNode path")
|
||||
}
|
||||
|
||||
if r.BadNodes()[0].Err().Error() != "merkledag: not found" {
|
||||
t.Errorf("unexpected badNode error: %s", r.BadNodes()[0].Err().Error())
|
||||
}
|
||||
n++
|
||||
}
|
||||
|
||||
if r.BadNodes()[0].Path().Cid().String() != p0.Cid().String() {
|
||||
t.Error("unexpected badNode path")
|
||||
if n != 1 {
|
||||
t.Errorf("unexpected verify result count: %d", n)
|
||||
}
|
||||
|
||||
if r.BadNodes()[0].Err().Error() != "merkledag: not found" {
|
||||
t.Errorf("unexpected badNode error: %s", r.BadNodes()[0].Err().Error())
|
||||
}
|
||||
n++
|
||||
}
|
||||
|
||||
if n != 1 {
|
||||
t.Errorf("unexpected verify result count: %d", n)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ func TestBasicPubSub(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
nds, apis, err := makeAPISwarm(ctx, true, 2)
|
||||
apis, err := makeAPISwarm(ctx, true, 2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -46,7 +46,12 @@ func TestBasicPubSub(t *testing.T) {
|
||||
t.Errorf("got invalid data: %s", string(m.Data()))
|
||||
}
|
||||
|
||||
if m.From() != nds[1].Identity {
|
||||
self1, err := apis[1].Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if m.From() != self1.ID() {
|
||||
t.Errorf("m.From didn't match")
|
||||
}
|
||||
|
||||
@ -59,7 +64,12 @@ func TestBasicPubSub(t *testing.T) {
|
||||
t.Fatalf("got incorrect number of peers: %d", len(peers))
|
||||
}
|
||||
|
||||
if peers[0] != nds[0].Identity {
|
||||
self0, err := apis[0].Key().Self(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if peers[0] != self0.ID() {
|
||||
t.Errorf("peer didn't match")
|
||||
}
|
||||
|
||||
|
||||
@ -19,22 +19,21 @@ import (
|
||||
"github.com/ipfs/go-ipfs/core/coreapi"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
"github.com/ipfs/go-ipfs/core/coreunix"
|
||||
mock "github.com/ipfs/go-ipfs/core/mock"
|
||||
"github.com/ipfs/go-ipfs/keystore"
|
||||
"github.com/ipfs/go-ipfs/repo"
|
||||
|
||||
ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
|
||||
mocknet "gx/ipfs/QmRBaUEQEeFWywfrZJ64QgsmvcqgLSK3VbvGMR2NM2Edpf/go-libp2p/p2p/net/mock"
|
||||
"gx/ipfs/QmRBaUEQEeFWywfrZJ64QgsmvcqgLSK3VbvGMR2NM2Edpf/go-libp2p/p2p/net/mock"
|
||||
cbor "gx/ipfs/QmRoARq3nkUb13HSKZGepCZSWe5GrVPwx7xURJGZ7KWv9V/go-ipld-cbor"
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
peer "gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
|
||||
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
"gx/ipfs/QmY5Grm8pJdiSSVsYxx4uNRgweY72EmYwuSDbRnbFok3iY/go-libp2p-peer"
|
||||
pstore "gx/ipfs/QmZ9zH2FnLcxv1xyzFeUpDUeo55xEhZQHgveZijcxr7TLj/go-libp2p-peerstore"
|
||||
unixfs "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
|
||||
config "gx/ipfs/QmcZfkbgwwwH5ZLTQRHkSQBDiDqd3skY2eU6MZRgWuXcse/go-ipfs-config"
|
||||
"gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
|
||||
"gx/ipfs/QmcZfkbgwwwH5ZLTQRHkSQBDiDqd3skY2eU6MZRgWuXcse/go-ipfs-config"
|
||||
mdag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
|
||||
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
|
||||
datastore "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore"
|
||||
"gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore"
|
||||
syncds "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore/sync"
|
||||
)
|
||||
|
||||
@ -47,7 +46,7 @@ var helloStr = "hello, world!"
|
||||
// `echo -n | ipfs add`
|
||||
var emptyFile = "/ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"
|
||||
|
||||
func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNode, []coreiface.CoreAPI, error) {
|
||||
func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
|
||||
mn := mocknet.New(ctx)
|
||||
|
||||
nodes := make([]*core.IpfsNode, n)
|
||||
@ -58,17 +57,17 @@ func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNo
|
||||
if fullIdentity {
|
||||
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := peer.IDFromPublicKey(pk)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
kbytes, err := sk.Bytes()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ident = config.Identity{
|
||||
@ -100,18 +99,18 @@ func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNo
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
nodes[i] = node
|
||||
apis[i], err = coreapi.NewCoreAPI(node)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err := mn.LinkAll()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bsinf := core.BootstrapConfigWithPeers(
|
||||
@ -122,20 +121,20 @@ func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNo
|
||||
|
||||
for _, n := range nodes[1:] {
|
||||
if err := n.Bootstrap(bsinf); err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, apis, nil
|
||||
return apis, nil
|
||||
}
|
||||
|
||||
func makeAPI(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error) {
|
||||
nd, api, err := makeAPISwarm(ctx, false, 1)
|
||||
func makeAPI(ctx context.Context) (coreiface.CoreAPI, error) {
|
||||
api, err := makeAPISwarm(ctx, false, 1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nd[0], api[0], nil
|
||||
return api[0], nil
|
||||
}
|
||||
|
||||
func strFile(data string) func() files.Node {
|
||||
@ -174,7 +173,7 @@ func wrapped(name string) func(f files.Node) files.Node {
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -631,7 +630,7 @@ func TestAdd(t *testing.T) {
|
||||
|
||||
func TestAddPinned(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -653,7 +652,7 @@ func TestAddPinned(t *testing.T) {
|
||||
|
||||
func TestAddHashOnly(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -678,12 +677,12 @@ func TestAddHashOnly(t *testing.T) {
|
||||
|
||||
func TestGetEmptyFile(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = coreunix.Add(node, strings.NewReader(""))
|
||||
_, err = api.Unixfs().Add(ctx, files.NewBytesFile([]byte{}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -710,12 +709,12 @@ func TestGetEmptyFile(t *testing.T) {
|
||||
|
||||
func TestGetDir(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
edir := unixfs.EmptyDirNode()
|
||||
err = node.DAG.Add(ctx, edir)
|
||||
_, err = api.Dag().Put(ctx, bytes.NewReader(edir.RawData()), options.Dag.Codec(cid.DagProtobuf), options.Dag.InputEnc("raw"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -742,13 +741,13 @@ func TestGetDir(t *testing.T) {
|
||||
|
||||
func TestGetNonUnixfs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
nd := new(mdag.ProtoNode)
|
||||
err = node.DAG.Add(ctx, nd)
|
||||
_, err = api.Dag().Put(ctx, bytes.NewReader(nd.RawData()), options.Dag.Codec(nd.CidBuilder().GetCodec()), options.Dag.InputEnc("raw"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -761,21 +760,17 @@ func TestGetNonUnixfs(t *testing.T) {
|
||||
|
||||
func TestLs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
r := strings.NewReader("content-of-file")
|
||||
k, _, err := coreunix.AddWrapped(node, r, "name-of-file")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
parts := strings.Split(k, "/")
|
||||
if len(parts) != 2 {
|
||||
t.Errorf("unexpected path: %s", k)
|
||||
}
|
||||
p, err := coreiface.ParsePath("/ipfs/" + parts[0])
|
||||
p, err := api.Unixfs().Add(ctx, files.NewMapDirectory(map[string]files.Node{
|
||||
"0": files.NewMapDirectory(map[string]files.Node{
|
||||
"name-of-file": files.NewReaderFile(r),
|
||||
}),
|
||||
}))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -801,21 +796,17 @@ func TestLs(t *testing.T) {
|
||||
|
||||
func TestEntriesExpired(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
r := strings.NewReader("content-of-file")
|
||||
k, _, err := coreunix.AddWrapped(node, r, "name-of-file")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
parts := strings.Split(k, "/")
|
||||
if len(parts) != 2 {
|
||||
t.Errorf("unexpected path: %s", k)
|
||||
}
|
||||
p, err := coreiface.ParsePath("/ipfs/" + parts[0])
|
||||
p, err := api.Unixfs().Add(ctx, files.NewMapDirectory(map[string]files.Node{
|
||||
"0": files.NewMapDirectory(map[string]files.Node{
|
||||
"name-of-file": files.NewReaderFile(r),
|
||||
}),
|
||||
}))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -848,12 +839,12 @@ func TestEntriesExpired(t *testing.T) {
|
||||
|
||||
func TestLsEmptyDir(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = node.DAG.Add(ctx, unixfs.EmptyDirNode())
|
||||
_, err = api.Unixfs().Add(ctx, files.NewMapDirectory(map[string]files.Node{"0": files.NewSliceDirectory([]files.DirEntry{})}))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -876,7 +867,7 @@ func TestLsEmptyDir(t *testing.T) {
|
||||
// TODO(lgierth) this should test properly, with len(links) > 0
|
||||
func TestLsNonUnixfs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
node, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -886,7 +877,7 @@ func TestLsNonUnixfs(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = node.DAG.Add(ctx, nd)
|
||||
_, err = api.Dag().Put(ctx, bytes.NewReader(nd.RawData()), options.Dag.Codec(cid.DagCBOR), options.Dag.InputEnc("raw"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -933,7 +924,7 @@ func (f *closeTestF) Close() error {
|
||||
|
||||
func TestAddCloses(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
_, api, err := makeAPI(ctx)
|
||||
api, err := makeAPI(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user