Beispiel #1
0
func TestPBDecode(t *testing.T) {
	c := mcproto.Multicodec(&PBNode{})
	buf := bytes.NewBuffer(testfile)
	dec := c.Decoder(buf)

	// pass the /mdagv1
	if err := mc.ConsumeHeader(buf, Header); err != nil {
		t.Fatal("failed to consume header", err)
	}

	var pbn PBNode
	if err := dec.Decode(&pbn); err != nil {
		t.Fatal("failed to decode", err)
	}

	if len(pbn.Links) < 7 {
		t.Fatal("incorrect number of links")
	}
	if len(pbn.Data) == 0 {
		t.Error("should have some data")
	}

	findLink := func(s string) *PBLink {
		for _, l := range pbn.Links {
			if *l.Name == s {
				return l
			}
		}
		return nil
	}

	makefile := findLink("Makefile")
	if makefile == nil {
		t.Error("did not find Makefile")
	} else {
		if *makefile.Tsize < 700 || *makefile.Tsize > 4096 {
			t.Error("makefile incorrect size")
		}
	}
}
Beispiel #2
0
func Multicodec() mc.Multicodec {
	var n *PBNode
	return &codec{mcproto.Multicodec(n)}
}