Skip to content

Commit

Permalink
test: add dirbuilder tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu committed Sep 12, 2016
1 parent a547d88 commit 0750c87
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions unixfs/io/dirbuilder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io

import (
"context"
"io/ioutil"
"testing"

testu "github.com/ipfs/go-ipfs/unixfs/test"
)

func TestEmptyNode(t *testing.T) {
n := NewEmptyDirectory()
if len(n.Links) != 0 {
t.Fatal("empty node should have 0 links")
}
}

func TestDirBuilder(t *testing.T) {
dserv := testu.GetDAGServ()
ctx, closer := context.WithCancel(context.Background())
defer closer()
inbuf, node := testu.GetRandomNode(t, dserv, 1024)
key := node.Cid()

b := NewDirectory(dserv)

b.AddChild(ctx, "random", key)

dir := b.GetNode()
outn, err := dir.GetLinkedNode(ctx, dserv, "random")
if err != nil {
t.Fatal(err)
}

reader, err := NewDagReader(ctx, outn, dserv)
if err != nil {
t.Fatal(err)
}

outbuf, err := ioutil.ReadAll(reader)
if err != nil {
t.Fatal(err)
}

err = testu.ArrComp(inbuf, outbuf)
if err != nil {
t.Fatal(err)
}

}

0 comments on commit 0750c87

Please sign in to comment.