]> Sergey Matveev's repositories - btrtrc.git/blobdiff - tracker/udp_test.go
chore: remove refs to deprecated io/ioutil
[btrtrc.git] / tracker / udp_test.go
index 323047306f02c6f7ac60cfc1b6e698b712de5f79..232aeb1973a51f0229b6591894473ea4a61c94c8 100644 (file)
@@ -6,7 +6,7 @@ import (
        "crypto/rand"
        "errors"
        "fmt"
-       "io/ioutil"
+       "io"
        "net"
        "net/url"
        "sync"
@@ -15,14 +15,16 @@ import (
 
        "github.com/anacrolix/dht/v2/krpc"
        _ "github.com/anacrolix/envpprof"
-       "github.com/anacrolix/torrent/tracker/udp"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
+
+       "github.com/anacrolix/torrent/tracker/udp"
 )
 
 var trackers = []string{
        "udp://tracker.opentrackr.org:1337/announce",
        "udp://tracker.openbittorrent.com:6969/announce",
+       "udp://localhost:42069",
 }
 
 func TestAnnounceLocalhost(t *testing.T) {
@@ -40,7 +42,7 @@ func TestAnnounceLocalhost(t *testing.T) {
                },
        }
        var err error
-       srv.pc, err = net.ListenPacket("udp", ":0")
+       srv.pc, err = net.ListenPacket("udp", "localhost:0")
        require.NoError(t, err)
        defer srv.pc.Close()
        go func() {
@@ -92,7 +94,7 @@ func TestUDPTracker(t *testing.T) {
                t.Skip(err)
        }
        require.NoError(t, err)
-       t.Log(ar)
+       t.Logf("%+v", ar)
 }
 
 func TestAnnounceRandomInfoHashThirdParty(t *testing.T) {
@@ -143,7 +145,7 @@ func TestAnnounceRandomInfoHashThirdParty(t *testing.T) {
 
 // Check that URLPath option is done correctly.
 func TestURLPathOption(t *testing.T) {
-       conn, err := net.ListenUDP("udp", nil)
+       conn, err := net.ListenPacket("udp", "localhost:0")
        if err != nil {
                panic(err)
        }
@@ -161,6 +163,7 @@ func TestURLPathOption(t *testing.T) {
                announceErr <- err
        }()
        var b [512]byte
+       // conn.SetReadDeadline(time.Now().Add(time.Second))
        _, addr, _ := conn.ReadFrom(b[:])
        r := bytes.NewReader(b[:])
        var h udp.RequestHeader
@@ -176,7 +179,7 @@ func TestURLPathOption(t *testing.T) {
        r = bytes.NewReader(b[:n])
        udp.Read(r, &h)
        udp.Read(r, &AnnounceRequest{})
-       all, _ := ioutil.ReadAll(r)
+       all, _ := io.ReadAll(r)
        if string(all) != "\x02\x09/announce" {
                t.FailNow()
        }