github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/unixfs/format_test.go (about)

     1  package unixfs
     2  
     3  import (
     4  	"testing"
     5  
     6  	proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
     7  	pb "github.com/jbenet/go-ipfs/unixfs/pb"
     8  )
     9  
    10  func TestMultiBlock(t *testing.T) {
    11  	mbf := new(MultiBlock)
    12  	for i := 0; i < 15; i++ {
    13  		mbf.AddBlockSize(100)
    14  	}
    15  
    16  	mbf.Data = make([]byte, 128)
    17  
    18  	b, err := mbf.GetBytes()
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	pbn := new(pb.Data)
    24  	err = proto.Unmarshal(b, pbn)
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  
    29  	ds, err := DataSize(b)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  
    34  	if ds != (100*15)+128 {
    35  		t.Fatal("Datasize calculations incorrect!")
    36  	}
    37  }