Skip to content

Commit

Permalink
fixify tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <[email protected]>
  • Loading branch information
whyrusleeping committed Dec 5, 2015
1 parent 559860c commit 742f6da
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 2 additions & 8 deletions core/coreunix/add_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package coreunix

import (
"os"
"path"
"testing"

"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
Expand All @@ -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{
Expand All @@ -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)
}
}
3 changes: 3 additions & 0 deletions mfs/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
12 changes: 12 additions & 0 deletions mfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0200-unixfs-ls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 742f6da

Please sign in to comment.