github.com/anacrolix/torrent@v1.61.0/issue-949_test.go (about)

     1  package torrent
     2  
     3  import (
     4  	"testing"
     5  
     6  	qt "github.com/go-quicktest/qt"
     7  
     8  	"github.com/anacrolix/torrent/metainfo"
     9  )
    10  
    11  func TestIssue949LastPieceZeroPadding(t *testing.T) {
    12  	// This torrent has a padding file after the last file listed in the v2 info file tree.
    13  	mi, err := metainfo.LoadFromFile("testdata/issue-949.torrent")
    14  	if err != nil {
    15  		panic(err)
    16  	}
    17  	info, err := mi.UnmarshalInfo()
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  	lastPiece := info.Piece(info.NumPieces() - 1)
    22  	qt.Assert(t, qt.IsTrue(info.FilesArePieceAligned()))
    23  	// Check the v1 piece length includes the trailing padding file.
    24  	qt.Check(t, qt.Equals(lastPiece.V1Length(), info.PieceLength))
    25  	// The v2 piece should only include the file data, which fits inside the piece length for this
    26  	// file.
    27  	qt.Check(t, qt.Equals(lastPiece.Length(), int64(3677645)))
    28  }