From: Matt Joiner Date: Tue, 27 Aug 2024 00:03:22 +0000 (+1000) Subject: Fix empty Info marshalling test X-Git-Tag: v1.57.0~10 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=8bbecdae722480078d89b95e6b1c0f464790f180;p=btrtrc.git Fix empty Info marshalling test --- diff --git a/metainfo/info.go b/metainfo/info.go index 015876ed..e58bb10e 100644 --- a/metainfo/info.go +++ b/metainfo/info.go @@ -13,11 +13,12 @@ import ( // The info dictionary. See BEP 3 and BEP 52. type Info struct { - PieceLength int64 `bencode:"piece length"` // BEP3 - Pieces []byte `bencode:"pieces,omitempty"` // BEP3 - Name string `bencode:"name"` // BEP3 - NameUtf8 string `bencode:"name.utf-8,omitempty"` - Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files + PieceLength int64 `bencode:"piece length"` // BEP3 + // BEP 3. This can be omitted because isn't needed in non-hybrid v2 infos. See BEP 52. + Pieces []byte `bencode:"pieces,omitempty"` + Name string `bencode:"name"` // BEP3 + NameUtf8 string `bencode:"name.utf-8,omitempty"` + Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files ExtendedFileAttrs Private *bool `bencode:"private,omitempty"` // BEP27 // TODO: Document this field. diff --git a/metainfo/info_test.go b/metainfo/info_test.go index d65ac2f1..9fd3bded 100644 --- a/metainfo/info_test.go +++ b/metainfo/info_test.go @@ -1,6 +1,7 @@ package metainfo import ( + g "github.com/anacrolix/generics" "testing" "github.com/stretchr/testify/assert" @@ -10,6 +11,7 @@ import ( func TestMarshalInfo(t *testing.T) { var info Info + g.MakeSliceWithLength(&info.Pieces, 0) b, err := bencode.Marshal(info) assert.NoError(t, err) assert.EqualValues(t, "d4:name0:12:piece lengthi0e6:pieces0:e", string(b))