)
func TestClientDefault(t *testing.T) {
- cl, err := NewClient(TestingConfig())
+ cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
cl.Close()
}
}
func TestBoltPieceCompletionClosedWhenClientClosed(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
pc, err := storage.NewBoltPieceCompletion(cfg.DataDir)
require.NoError(t, err)
ci := storage.NewFileWithCompletion(cfg.DataDir, pc)
}
func TestAddDropTorrent(t *testing.T) {
- cl, err := NewClient(TestingConfig())
+ cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
dir, mi := testutil.GreetingTestTorrent()
dir, mi := testutil.GreetingTestTorrent()
defer os.RemoveAll(dir)
cl := &Client{
- config: TestingConfig(),
+ config: TestingConfig(t),
}
cl.initLogger()
tor := cl.newTorrent(
mi.HashInfoBytes(),
- storage.NewFileWithCompletion(TestingTempDir.NewSub(), storage.NewMapPieceCompletion()),
+ storage.NewFileWithCompletion(t.TempDir(), storage.NewMapPieceCompletion()),
)
tor.setChunkSize(2)
tor.cl.lock()
}
func TestAddDropManyTorrents(t *testing.T) {
- cl, err := NewClient(TestingConfig())
+ cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
for i := range iter.N(1000) {
}
func TestMergingTrackersByAddingSpecs(t *testing.T) {
- cl, err := NewClient(TestingConfig())
+ cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
spec := TorrentSpec{}
// We read from a piece which is marked completed, but is missing data.
func TestCompletedPieceWrongSize(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DefaultStorage = badStorage{}
cl, err := NewClient(cfg)
require.NoError(t, err)
}
func BenchmarkAddLargeTorrent(b *testing.B) {
- cfg := TestingConfig()
+ cfg := TestingConfig(b)
cfg.DisableTCP = true
cfg.DisableUTP = true
cl, err := NewClient(cfg)
func TestResponsive(t *testing.T) {
seederDataDir, mi := testutil.GreetingTestTorrent()
defer os.RemoveAll(seederDataDir)
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.Seed = true
cfg.DataDir = seederDataDir
seeder, err := NewClient(cfg)
leecherDataDir, err := ioutil.TempDir("", "")
require.Nil(t, err)
defer os.RemoveAll(leecherDataDir)
- cfg = TestingConfig()
+ cfg = TestingConfig(t)
cfg.DataDir = leecherDataDir
leecher, err := NewClient(cfg)
require.Nil(t, err)
func TestTorrentDroppedDuringResponsiveRead(t *testing.T) {
seederDataDir, mi := testutil.GreetingTestTorrent()
defer os.RemoveAll(seederDataDir)
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.Seed = true
cfg.DataDir = seederDataDir
seeder, err := NewClient(cfg)
leecherDataDir, err := ioutil.TempDir("", "")
require.Nil(t, err)
defer os.RemoveAll(leecherDataDir)
- cfg = TestingConfig()
+ cfg = TestingConfig(t)
cfg.DataDir = leecherDataDir
leecher, err := NewClient(cfg)
require.Nil(t, err)
func TestDhtInheritBlocklist(t *testing.T) {
ipl := iplist.New(nil)
require.NotNil(t, ipl)
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.IPBlocklist = ipl
cfg.NoDHT = false
cl, err := NewClient(cfg)
// Check that stuff is merged in subsequent AddTorrentSpec for the same
// infohash.
func TestAddTorrentSpecMerging(t *testing.T) {
- cl, err := NewClient(TestingConfig())
+ cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
dir, mi := testutil.GreetingTestTorrent()
func TestTorrentDroppedBeforeGotInfo(t *testing.T) {
dir, mi := testutil.GreetingTestTorrent()
os.RemoveAll(dir)
- cl, _ := NewClient(TestingConfig())
+ cl, _ := NewClient(TestingConfig(t))
defer cl.Close()
tt, _, _ := cl.AddTorrentSpec(&TorrentSpec{
InfoHash: mi.HashInfoBytes(),
require.NoError(t, greetingData.Piece(p).MarkComplete())
}
}
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
// TODO: Disable network option?
cfg.DisableTCP = true
cfg.DisableUTP = true
}
func TestAddMetainfoWithNodes(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.ListenHost = func(string) string { return "" }
cfg.NoDHT = false
cfg.DhtStartingNodes = func(string) dht.StartingNodesGetter { return func() ([]dht.Addr, error) { return nil, nil } }
func testDownloadCancel(t *testing.T, ps testDownloadCancelParams) {
greetingTempDir, mi := testutil.GreetingTestTorrent()
defer os.RemoveAll(greetingTempDir)
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.Seed = true
cfg.DataDir = greetingTempDir
seeder, err := NewClient(cfg)
// Ensure that it's an error for a peer to send an invalid have message.
func TestPeerInvalidHave(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DropMutuallyCompletePeers = false
cl, err := NewClient(cfg)
require.NoError(t, err)
func TestPieceCompletedInStorageButNotClient(t *testing.T) {
greetingTempDir, greetingMetainfo := testutil.GreetingTestTorrent()
defer os.RemoveAll(greetingTempDir)
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DataDir = greetingTempDir
- seeder, err := NewClient(TestingConfig())
+ seeder, err := NewClient(TestingConfig(t))
require.NoError(t, err)
seeder.AddTorrentSpec(&TorrentSpec{
InfoBytes: greetingMetainfo.InfoBytes,
// Check that when the listen port is 0, all the protocols listened on have
// the same port, and it isn't zero.
func TestClientDynamicListenPortAllProtocols(t *testing.T) {
- cl, err := NewClient(TestingConfig())
+ cl, err := NewClient(TestingConfig(t))
require.NoError(t, err)
defer cl.Close()
port := cl.LocalPort()
}
func TestClientDynamicListenTCPOnly(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DisableUTP = true
cfg.DisableTCP = false
cl, err := NewClient(cfg)
}
func TestClientDynamicListenUTPOnly(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DisableTCP = true
cfg.DisableUTP = false
cl, err := NewClient(cfg)
func TestSetMaxEstablishedConn(t *testing.T) {
var tts []*Torrent
ih := testutil.GreetingMetaInfo().HashInfoBytes()
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DisableAcceptRateLimiting = true
cfg.DropDuplicatePeerIds = true
for i := range iter.N(3) {
// Test that the leecher can download a torrent in its entirety from the seeder. Note that the
// seeder config is done first.
func testSeederLeecherPair(t *testing.T, seeder func(*ClientConfig), leecher func(*ClientConfig)) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.Seed = true
cfg.DataDir = filepath.Join(cfg.DataDir, "server")
os.Mkdir(cfg.DataDir, 0755)
for i := 0; i < 100; i++ {
makeMagnet(t, server, cfg.DataDir, fmt.Sprintf("test%d", i+2))
}
- cfg = TestingConfig()
+ cfg = TestingConfig(t)
cfg.DataDir = filepath.Join(cfg.DataDir, "client")
leecher(cfg)
client, err := NewClient(cfg)
if s != nil {
defer s.Close()
}
- cfg := TestingConfig().SetListenAddr(":50007")
+ cfg := TestingConfig(t).SetListenAddr(":50007")
cl, err := NewClient(cfg)
require.Error(t, err)
require.Nil(t, cl)
}
func TestClientHasDhtServersWhenUtpDisabled(t *testing.T) {
- cc := TestingConfig()
+ cc := TestingConfig(t)
cc.DisableUTP = true
cc.NoDHT = false
cl, err := NewClient(cc)
func TestIssue335(t *testing.T) {
dir, mi := testutil.GreetingTestTorrent()
defer os.RemoveAll(dir)
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.Seed = false
cfg.Debug = true
cfg.DataDir = dir
}
func TestClientDisabledImplicitNetworksButDhtEnabled(t *testing.T) {
- cfg := TestingConfig()
+ cfg := TestingConfig(t)
cfg.DisableTCP = true
cfg.DisableUTP = true
cfg.NoDHT = false