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

import (
	"testing"

6 7
	proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"

8
	pb "github.com/ipfs/go-ipfs/unixfs/pb"
9 10
)

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

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

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

25
	pbn := new(pb.Data)
26 27 28 29 30 31 32 33 34 35 36 37 38 39
	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!")
	}
}