]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix empty Info marshalling test
authorMatt Joiner <anacrolix@gmail.com>
Tue, 27 Aug 2024 00:03:22 +0000 (10:03 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 27 Aug 2024 00:03:22 +0000 (10:03 +1000)
metainfo/info.go
metainfo/info_test.go

index 015876ed8b10776792e841f680c2d3b63e775bee..e58bb10e5821297aa12888d95421b7495a4715d2 100644 (file)
@@ -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.
index d65ac2f1ccade07c615a24e395ef7a2fe2f6fab2..9fd3bdedfc08ecb7dcd338f4423fe9855abbeec1 100644 (file)
@@ -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))