metainfo: Omit empty Metainfo.InfoBytes
This commit is contained in:
parent
163a63f9a7
commit
da9cbc7cf0
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type MetaInfo struct {
|
||||
InfoBytes bencode.Bytes `bencode:"info"`
|
||||
InfoBytes bencode.Bytes `bencode:"info,omitempty"`
|
||||
Announce string `bencode:"announce,omitempty"`
|
||||
AnnounceList AnnounceList `bencode:"announce-list,omitempty"`
|
||||
Nodes []Node `bencode:"nodes,omitempty"`
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package metainfo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -61,3 +62,13 @@ func TestUnmarshalBadMetainfoNodes(t *testing.T) {
|
|||
err := bencode.Unmarshal([]byte("d5:nodesl1:ai42eee"), &mi)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestMetainfoEmptyInfoBytes(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
require.NoError(t, (&MetaInfo{
|
||||
// Include a non-empty field that comes after "info".
|
||||
UrlList: []string{"hello"},
|
||||
}).Write(&buf))
|
||||
var mi MetaInfo
|
||||
require.NoError(t, bencode.Unmarshal(buf.Bytes(), &mi))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue