format_test.go 557 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
package unixfs

import (
	"testing"

	"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
)

func TestMultiBlock(t *testing.T) {
	mbf := new(MultiBlock)
	for i := 0; i < 15; i++ {
		mbf.AddBlockSize(100)
	}

	mbf.Data = make([]byte, 128)

	b, err := mbf.GetBytes()
	if err != nil {
		t.Fatal(err)
	}

	pbn := new(PBData)
	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!")
	}
}