From 742f6da453bd9b0cc0638417049042297edd0e30 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 4 Dec 2015 21:09:26 -0800 Subject: [PATCH] fixify tests License: MIT Signed-off-by: Jeromy --- core/coreunix/add.go | 4 ++-- core/coreunix/add_test.go | 10 ++-------- mfs/ops.go | 3 +++ mfs/system.go | 12 ++++++++++++ test/sharness/t0200-unixfs-ls.sh | 4 ++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/core/coreunix/add.go b/core/coreunix/add.go index 8180b5bef33..6ca989b2649 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -280,16 +280,16 @@ func AddR(n *core.IpfsNode, root string) (key string, err error) { // the directory, and and error if any. func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, *dag.Node, error) { file := files.NewReaderFile(filename, filename, ioutil.NopCloser(r), nil) - dir := files.NewSliceFile("", "", []files.File{file}) fileAdder, err := NewAdder(n.Context(), n, nil) if err != nil { return "", nil, err } + fileAdder.Wrap = true unlock := n.Blockstore.PinLock() defer unlock() - err = fileAdder.addDir(dir) + err = fileAdder.AddFile(file) if err != nil { return "", nil, err } diff --git a/core/coreunix/add_test.go b/core/coreunix/add_test.go index 6d4bfb17656..279d7ce74d5 100644 --- a/core/coreunix/add_test.go +++ b/core/coreunix/add_test.go @@ -1,8 +1,6 @@ package coreunix import ( - "os" - "path" "testing" "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" @@ -13,10 +11,6 @@ import ( ) func TestAddRecursive(t *testing.T) { - here, err := os.Getwd() - if err != nil { - t.Fatal(err) - } r := &repo.Mock{ C: config.Config{ Identity: config.Identity{ @@ -29,9 +23,9 @@ func TestAddRecursive(t *testing.T) { if err != nil { t.Fatal(err) } - if k, err := AddR(node, path.Join(here, "test_data")); err != nil { + if k, err := AddR(node, "test_data"); err != nil { t.Fatal(err) } else if k != "QmWCCga8AbTyfAQ7pTnGT6JgmRMAB3Qp8ZmTEFi5q5o8jC" { - t.Fatal("keys do not match") + t.Fatal("keys do not match: ", k) } } diff --git a/mfs/ops.go b/mfs/ops.go index c7309a31d9d..ebb1932edeb 100644 --- a/mfs/ops.go +++ b/mfs/ops.go @@ -101,6 +101,9 @@ func PutNode(r *Root, path string, nd *dag.Node) error { // Mkdir creates a directory at 'path' under the directory 'd', creating // intermediary directories as needed if 'parents' is set to true func Mkdir(r *Root, pth string, parents bool) error { + if pth == "" { + panic("empty path") + } parts := path.SplitList(pth) if parts[0] == "" { parts = parts[1:] diff --git a/mfs/system.go b/mfs/system.go index a7aeb2b20f6..2cfc4e201fd 100644 --- a/mfs/system.go +++ b/mfs/system.go @@ -124,9 +124,21 @@ func (kr *Root) closeChild(name string, nd *dag.Node) error { } func (kr *Root) Close() error { + nd, err := kr.GetValue().GetNode() + if err != nil { + return err + } + + k, err := kr.dserv.Add(nd) + if err != nil { + return err + } + if kr.repub != nil { + kr.repub.Update(k) return kr.repub.Close() } + return nil } diff --git a/test/sharness/t0200-unixfs-ls.sh b/test/sharness/t0200-unixfs-ls.sh index 1b889987d4d..ea386b98ce5 100755 --- a/test/sharness/t0200-unixfs-ls.sh +++ b/test/sharness/t0200-unixfs-ls.sh @@ -27,12 +27,12 @@ test_ls_cmd() { cat <<-\EOF >expected_add && added QmQNd6ubRXaNG6Prov8o6vk3bn6eWsj9FxLGrAVDUAGkGe testData/d1/128 added QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN testData/d1/a - added QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss testData/d1 added QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd testData/d2/1024 added QmaRGe7bVmVaLmxbrMiVNXqW4pRNNp3xq7hFtyRKA3mtJL testData/d2/a - added QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy testData/d2 added QmeomffUNfmQy76CQGy9NdmqEnnHU9soCexBnGU3ezPHVH testData/f1 added QmNtocSs7MoDkJMc1RkyisCSKvLadujPsfJfSdJ3e1eA1M testData/f2 + added QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss testData/d1 + added QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy testData/d2 added QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj testData EOF test_cmp expected_add actual_add