format_test.go 616 Bytes
Newer Older
1 2 3 4 5
package unixfs

import (
	"testing"

6 7
	proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
	pb "github.com/jbenet/go-ipfs/unixfs/pb"
8 9
)

10 11 12
func TestFSNode(t *testing.T) {
	fsn := new(FSNode)
	fsn.Type = TFile
13
	for i := 0; i < 15; i++ {
14
		fsn.AddBlockSize(100)
15 16
	}

17
	fsn.Data = make([]byte, 128)
18

19
	b, err := fsn.GetBytes()
20 21 22 23
	if err != nil {
		t.Fatal(err)
	}

24
	pbn := new(pb.Data)
25 26 27 28 29 30 31 32 33 34 35 36 37 38
	err = proto.Unmarshal(b, pbn)
	if err != nil {
		t.Fatal(err)
	}

	ds, err := DataSize(b)
	if err != nil {
		t.Fatal(err)
	}

	if ds != (100*15)+128 {
		t.Fatal("Datasize calculations incorrect!")
	}
}