From: Matt Joiner Date: Mon, 12 Sep 2016 06:53:20 +0000 (+1000) Subject: Add test for issue #111 and #112 X-Git-Tag: v1.0.0~590 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=011838998e75fb57cadbb7db847205a89e13a417;p=btrtrc.git Add test for issue #111 and #112 --- diff --git a/torrent_test.go b/torrent_test.go index 60951663..f841e7f3 100644 --- a/torrent_test.go +++ b/torrent_test.go @@ -1,11 +1,16 @@ package torrent import ( + "os" + "path/filepath" "testing" + "github.com/anacrolix/missinggo" "github.com/bradfitz/iter" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/peer_protocol" ) @@ -89,3 +94,25 @@ func BenchmarkUpdatePiecePriorities(b *testing.B) { t.updatePiecePriorities() } } + +func TestEmptyFilesAndZeroPieceLength(t *testing.T) { + cl, err := NewClient(&TestingConfig) + require.NoError(t, err) + defer cl.Close() + ib, err := bencode.Marshal(metainfo.Info{ + Name: "empty", + Length: 0, + }) + require.NoError(t, err) + fp := filepath.Join(TestingConfig.DataDir, "empty") + os.Remove(fp) + assert.False(t, missinggo.FilePathExists(fp)) + tt, err := cl.AddTorrent(&metainfo.MetaInfo{ + InfoBytes: ib, + }) + require.NoError(t, err) + defer tt.Drop() + tt.DownloadAll() + require.True(t, cl.WaitAll()) + assert.True(t, missinggo.FilePathExists(fp)) +}