From 60828c461406401617acf568b9171b65baf88dea Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 23 Jun 2025 10:50:07 +1000 Subject: [PATCH] Refactor all use of github.com/frankban/quicktest to new go-quicktest/qt Claude did this. Pretty neat. Only took 18 months of waiting for it to get decent. --- bencode/bytes_test.go | 12 +++-- bencode/decode_test.go | 29 +++++------- bencode/fuzz_test.go | 22 ++++----- fs/stream-sintel_test.go | 5 ++- go.mod | 2 +- internal/alloclim/alloclim_test.go | 45 +++++++++---------- internal/nestedmaps/nestedmaps_test.go | 33 +++++++------- ltep_test.go | 38 ++++++++-------- metainfo/magnet-v2_test.go | 33 +++++++------- metainfo/magnet_test.go | 9 ++-- metainfo/metainfo_test.go | 25 +++++------ peer_protocol/decoder_test.go | 5 +-- peer_protocol/fuzz_test.go | 11 +++-- peer_protocol/reserved_test.go | 5 +-- .../ut-holepunch/ut-holepunch_test.go | 11 +++-- request-strategy-impls_test.go | 16 +++---- requesting_test.go | 10 ++--- reuse_test.go | 22 +++++---- segments/segments_test.go | 4 +- storage/mark-complete_test.go | 1 + test/leecher-storage.go | 6 +-- test/sqlite_test.go | 13 +++--- test/transfer_test.go | 4 +- tests/add-webseed-after-priorities/go.mod | 2 +- .../add-webseed-after-priorities/herp_test.go | 5 +-- tests/issue-952/issue-952_test.go | 13 +++--- tests/webseed-partial-seed/go.mod | 2 +- tests/webseed-partial-seed/herp_test.go | 5 +-- ut-holepunching_test.go | 33 ++++++-------- webseed-peer.go | 1 + webseed/request_test.go | 17 ++++--- webtorrent/fuzz_test.go | 7 ++- webtorrent/transport_test.go | 7 ++- worse-conns_test.go | 25 +++++------ 34 files changed, 218 insertions(+), 260 deletions(-) diff --git a/bencode/bytes_test.go b/bencode/bytes_test.go index 08b4f98b..f203dfa5 100644 --- a/bencode/bytes_test.go +++ b/bencode/bytes_test.go @@ -3,7 +3,7 @@ package bencode import ( "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestBytesMarshalNil(t *testing.T) { @@ -18,8 +18,7 @@ type structWithBytes struct { func TestMarshalNilStructBytes(t *testing.T) { _, err := Marshal(structWithBytes{B: Bytes("i42e")}) - c := qt.New(t) - c.Assert(err, qt.IsNotNil) + qt.Assert(t, qt.IsNotNil(err)) } type structWithOmitEmptyBytes struct { @@ -28,12 +27,11 @@ type structWithOmitEmptyBytes struct { } func TestMarshalNilStructBytesOmitEmpty(t *testing.T) { - c := qt.New(t) b, err := Marshal(structWithOmitEmptyBytes{B: Bytes("i42e")}) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) t.Logf("%q", b) var s structWithBytes err = Unmarshal(b, &s) - c.Assert(err, qt.IsNil) - c.Check(s.B, qt.DeepEquals, Bytes("i42e")) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.DeepEquals(s.B, Bytes("i42e"))) } diff --git a/bencode/decode_test.go b/bencode/decode_test.go index 16fa4487..c9b309e1 100644 --- a/bencode/decode_test.go +++ b/bencode/decode_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -150,7 +150,7 @@ func TestIgnoreUnmarshalTypeError(t *testing.T) { }{} require.Error(t, Unmarshal([]byte("d6:Normal5:helloe"), &s)) assert.NoError(t, Unmarshal([]byte("d6:Ignore5:helloe"), &s)) - qt.Assert(t, Unmarshal([]byte("d6:Ignorei42ee"), &s), qt.IsNil) + qt.Assert(t, qt.IsNil(Unmarshal([]byte("d6:Ignorei42ee"), &s))) assert.EqualValues(t, 42, s.Ignore) } @@ -183,19 +183,17 @@ func TestUnmarshalByteArray(t *testing.T) { func TestDecodeDictIntoUnsupported(t *testing.T) { // Any type that a dict shouldn't be unmarshallable into. var i int - c := qt.New(t) err := Unmarshal([]byte("d1:a1:be"), &i) t.Log(err) - c.Check(err, qt.IsNotNil) + qt.Check(t, qt.IsNotNil(err)) } func TestUnmarshalDictKeyNotString(t *testing.T) { // Any type that a dict shouldn't be unmarshallable into. var i int - c := qt.New(t) err := Unmarshal([]byte("di42e3:yese"), &i) t.Log(err) - c.Check(err, qt.Not(qt.IsNil)) + qt.Check(t, qt.IsNotNil(err)) } type arbitraryReader struct{} @@ -220,14 +218,13 @@ func decodeHugeString(t *testing.T, strLen int64, header, tail string, v interfa // Ensure that bencode strings in various places obey the Decoder.MaxStrLen field. func TestDecodeMaxStrLen(t *testing.T) { t.Parallel() - c := qt.New(t) test := func(header, tail string, v interface{}, maxStrLen MaxStrLen) { strLen := maxStrLen if strLen == 0 { strLen = DefaultDecodeMaxStrLen } - c.Assert(decodeHugeString(t, strLen, header, tail, v, maxStrLen), qt.IsNil) - c.Assert(decodeHugeString(t, strLen+1, header, tail, v, maxStrLen), qt.IsNotNil) + qt.Assert(t, qt.IsNil(decodeHugeString(t, strLen, header, tail, v, maxStrLen))) + qt.Assert(t, qt.IsNotNil(decodeHugeString(t, strLen+1, header, tail, v, maxStrLen))) } test("d%d:", "i0ee", new(interface{}), 0) test("%d:", "", new(interface{}), DefaultDecodeMaxStrLen) @@ -242,15 +239,14 @@ func TestDecodeStringIntoBoolPtr(t *testing.T) { var m struct { Private *bool `bencode:"private,omitempty"` } - c := qt.New(t) check := func(msg string, expectNil, expectTrue bool) { m.Private = nil - c.Check(Unmarshal([]byte(msg), &m), qt.IsNil, qt.Commentf("%q", msg)) + qt.Check(t, qt.IsNil(Unmarshal([]byte(msg), &m)), qt.Commentf("%q", msg)) if expectNil { - c.Check(m.Private, qt.IsNil) + qt.Check(t, qt.IsNil(m.Private)) } else { - if c.Check(m.Private, qt.IsNotNil, qt.Commentf("%q", msg)) { - c.Check(*m.Private, qt.Equals, expectTrue, qt.Commentf("%q", msg)) + if qt.Check(t, qt.IsNotNil(m.Private), qt.Commentf("%q", msg)) { + qt.Check(t, qt.Equals(*m.Private, expectTrue), qt.Commentf("%q", msg)) } } } @@ -270,7 +266,6 @@ func TestDecodeStringIntoBoolPtr(t *testing.T) { // To set expectations about how our Decoder should work. func TestJsonDecoderBehaviour(t *testing.T) { - c := qt.New(t) test := func(input string, items int, finalErr error) { d := json.NewDecoder(strings.NewReader(input)) actualItems := 0 @@ -283,8 +278,8 @@ func TestJsonDecoderBehaviour(t *testing.T) { } actualItems++ } - c.Check(firstErr, qt.Equals, finalErr) - c.Check(actualItems, qt.Equals, items) + qt.Check(t, qt.Equals(firstErr, finalErr)) + qt.Check(t, qt.Equals(actualItems, items)) } test("", 0, io.EOF) test("{}", 1, io.EOF) diff --git a/bencode/fuzz_test.go b/bencode/fuzz_test.go index d0dce71f..1f57b064 100644 --- a/bencode/fuzz_test.go +++ b/bencode/fuzz_test.go @@ -7,31 +7,28 @@ import ( "math/big" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/google/go-cmp/cmp" ) -var bencodeInterfaceChecker = qt.CmpEquals(cmp.Comparer(func(a, b *big.Int) bool { - return a.Cmp(b) == 0 -})) - func Fuzz(f *testing.F) { for _, ret := range random_encode_tests { f.Add([]byte(ret.expected)) } f.Fuzz(func(t *testing.T, b []byte) { - c := qt.New(t) var d interface{} err := Unmarshal(b, &d) if err != nil { t.Skip() } b0, err := Marshal(d) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) var d0 interface{} err = Unmarshal(b0, &d0) - c.Assert(err, qt.IsNil) - c.Assert(d0, bencodeInterfaceChecker, d) + qt.Assert(t, qt.IsNil(err)) + qt.Assert(t, qt.CmpEquals(d0, d, cmp.Comparer(func(a, b *big.Int) bool { + return a.Cmp(b) == 0 + }))) }) } @@ -40,14 +37,13 @@ func FuzzInterfaceRoundTrip(f *testing.F) { f.Add([]byte(ret.expected)) } f.Fuzz(func(t *testing.T, b []byte) { - c := qt.New(t) var d interface{} err := Unmarshal(b, &d) if err != nil { - c.Skip(err) + t.Skip(err) } b0, err := Marshal(d) - c.Assert(err, qt.IsNil) - c.Check(b0, qt.DeepEquals, b) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.DeepEquals(b0, b)) }) } diff --git a/fs/stream-sintel_test.go b/fs/stream-sintel_test.go index 3f780234..e78ec8a3 100644 --- a/fs/stream-sintel_test.go +++ b/fs/stream-sintel_test.go @@ -16,12 +16,13 @@ import ( "github.com/anacrolix/fuse" fusefs "github.com/anacrolix/fuse/fs" "github.com/anacrolix/missinggo/v2/panicif" + "github.com/go-quicktest/qt" + "golang.org/x/sync/errgroup" + "github.com/anacrolix/torrent" torrentfs "github.com/anacrolix/torrent/fs" "github.com/anacrolix/torrent/internal/testutil" "github.com/anacrolix/torrent/metainfo" - "github.com/go-quicktest/qt" - "golang.org/x/sync/errgroup" ) func copyFile(src, dst string) (err error) { diff --git a/go.mod b/go.mod index 0eeb162f..e0b55a30 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,6 @@ require ( github.com/dustin/go-humanize v1.0.0 github.com/edsrzf/mmap-go v1.1.0 github.com/elliotchance/orderedmap v1.4.0 - github.com/frankban/quicktest v1.14.6 github.com/fsnotify/fsnotify v1.5.4 github.com/go-llsqlite/adapter v0.0.0-20230927005056-7f5ce7f0c916 github.com/go-quicktest/qt v1.101.0 @@ -71,6 +70,7 @@ require ( github.com/bits-and-blooms/bitset v1.2.2 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/frankban/quicktest v1.14.6 // indirect github.com/go-llsqlite/crawshaw v0.5.6-0.20250312230104-194977a03421 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/internal/alloclim/alloclim_test.go b/internal/alloclim/alloclim_test.go index 5952804e..4dbd8c39 100644 --- a/internal/alloclim/alloclim_test.go +++ b/internal/alloclim/alloclim_test.go @@ -6,72 +6,67 @@ import ( "time" _ "github.com/anacrolix/envpprof" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestReserveOverMax(t *testing.T) { - c := qt.New(t) l := &Limiter{Max: 10} r := l.Reserve(20) - c.Assert(r.Wait(context.Background()), qt.IsNotNil) + qt.Assert(t, qt.IsNotNil(r.Wait(context.Background()))) } func TestImmediateAllow(t *testing.T) { - c := qt.New(t) l := &Limiter{Max: 10} r := l.Reserve(10) - c.Assert(r.Wait(context.Background()), qt.IsNil) + qt.Assert(t, qt.IsNil(r.Wait(context.Background()))) } func TestSimpleSequence(t *testing.T) { - c := qt.New(t) l := &Limiter{Max: 10} rs := make([]*Reservation, 0) rs = append(rs, l.Reserve(6)) rs = append(rs, l.Reserve(5)) rs = append(rs, l.Reserve(5)) - c.Assert(rs[0].Wait(context.Background()), qt.IsNil) + qt.Assert(t, qt.IsNil(rs[0].Wait(context.Background()))) ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Nanosecond)) - c.Assert(rs[1].Wait(ctx), qt.Equals, context.DeadlineExceeded) + qt.Assert(t, qt.Equals(rs[1].Wait(ctx), context.DeadlineExceeded)) go cancel() ctx, cancel = context.WithCancel(context.Background()) go cancel() - c.Assert(rs[2].Wait(ctx), qt.Equals, context.Canceled) + qt.Assert(t, qt.Equals(rs[2].Wait(ctx), context.Canceled)) go rs[0].Release() ctx, cancel = context.WithDeadline(context.Background(), time.Now().Add(time.Second)) - c.Assert(rs[1].Wait(ctx), qt.IsNil) + qt.Assert(t, qt.IsNil(rs[1].Wait(ctx))) go rs[1].Release() - c.Assert(rs[2].Wait(ctx), qt.IsNil) + qt.Assert(t, qt.IsNil(rs[2].Wait(ctx))) go rs[2].Release() go cancel() rs[2].Release() rs[1].Release() - c.Assert(l.Value(), qt.Equals, l.Max) + qt.Assert(t, qt.Equals(l.Value(), l.Max)) } func TestSequenceWithCancel(t *testing.T) { - c := qt.New(t) l := &Limiter{Max: 10} rs := make([]*Reservation, 0) rs = append(rs, l.Reserve(6)) rs = append(rs, l.Reserve(6)) rs = append(rs, l.Reserve(4)) rs = append(rs, l.Reserve(4)) - c.Assert(rs[0].Cancel(), qt.IsFalse) - c.Assert(func() { rs[1].Release() }, qt.PanicMatches, "not resolved") - c.Assert(rs[1].Cancel(), qt.IsTrue) - c.Assert(rs[2].Wait(context.Background()), qt.IsNil) + qt.Assert(t, qt.IsFalse(rs[0].Cancel())) + qt.Assert(t, qt.PanicMatches(func() { rs[1].Release() }, "not resolved")) + qt.Assert(t, qt.IsTrue(rs[1].Cancel())) + qt.Assert(t, qt.IsNil(rs[2].Wait(context.Background()))) rs[0].Release() - c.Assert(rs[3].Wait(context.Background()), qt.IsNil) - c.Assert(l.Value(), qt.Equals, int64(2)) + qt.Assert(t, qt.IsNil(rs[3].Wait(context.Background()))) + qt.Assert(t, qt.Equals(l.Value(), int64(2))) rs[1].Release() rs[2].Release() rs[3].Release() - c.Assert(l.Value(), qt.Equals, l.Max) + qt.Assert(t, qt.Equals(l.Value(), l.Max)) } func TestCancelWhileWaiting(t *testing.T) { - c := qt.New(t) l := &Limiter{Max: 10} rs := make([]*Reservation, 0) rs = append(rs, l.Reserve(6)) @@ -80,14 +75,14 @@ func TestCancelWhileWaiting(t *testing.T) { rs = append(rs, l.Reserve(4)) go rs[1].Cancel() err := rs[1].Wait(context.Background()) - c.Assert(err, qt.IsNotNil) + qt.Assert(t, qt.IsNotNil(err)) err = rs[2].Wait(context.Background()) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) ctx, cancel := context.WithCancel(context.Background()) go cancel() err = rs[3].Wait(ctx) - c.Assert(err, qt.Equals, context.Canceled) + qt.Assert(t, qt.Equals(err, context.Canceled)) rs[0].Drop() err = rs[3].Wait(ctx) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) } diff --git a/internal/nestedmaps/nestedmaps_test.go b/internal/nestedmaps/nestedmaps_test.go index 97916afb..3af16f8d 100644 --- a/internal/nestedmaps/nestedmaps_test.go +++ b/internal/nestedmaps/nestedmaps_test.go @@ -4,38 +4,37 @@ import ( "testing" g "github.com/anacrolix/generics" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestNestedMaps(t *testing.T) { - c := qt.New(t) var nest map[string]map[*int]map[byte][]int64 intKey := g.PtrTo(420) var root = Begin(&nest) var first = Next(root, "answer") var second = Next(first, intKey) var last = Next(second, 69) - c.Assert(root.Exists(), qt.IsFalse) - c.Assert(first.Exists(), qt.IsFalse) - c.Assert(second.Exists(), qt.IsFalse) - c.Assert(last.Exists(), qt.IsFalse) + qt.Assert(t, qt.IsFalse(root.Exists())) + qt.Assert(t, qt.IsFalse(first.Exists())) + qt.Assert(t, qt.IsFalse(second.Exists())) + qt.Assert(t, qt.IsFalse(last.Exists())) last.Set([]int64{4, 8, 15, 16, 23, 42}) - c.Assert(root.Exists(), qt.IsTrue) - c.Assert(first.Exists(), qt.IsTrue) - c.Assert(second.Exists(), qt.IsTrue) - c.Assert(last.Exists(), qt.IsTrue) - c.Assert(Next(second, 70).Exists(), qt.IsFalse) + qt.Assert(t, qt.IsTrue(root.Exists())) + qt.Assert(t, qt.IsTrue(first.Exists())) + qt.Assert(t, qt.IsTrue(second.Exists())) + qt.Assert(t, qt.IsTrue(last.Exists())) + qt.Assert(t, qt.IsFalse(Next(second, 70).Exists())) secondIntKey := g.PtrTo(1337) secondPath := Next(Next(Next(Begin(&nest), "answer"), secondIntKey), 42) secondPath.Set(nil) - c.Assert(secondPath.Exists(), qt.IsTrue) + qt.Assert(t, qt.IsTrue(secondPath.Exists())) last.Delete() - c.Assert(last.Exists(), qt.IsFalse) - c.Assert(second.Exists(), qt.IsFalse) - c.Assert(root.Exists(), qt.IsTrue) - c.Assert(first.Exists(), qt.IsTrue) + qt.Assert(t, qt.IsFalse(last.Exists())) + qt.Assert(t, qt.IsFalse(second.Exists())) + qt.Assert(t, qt.IsTrue(root.Exists())) + qt.Assert(t, qt.IsTrue(first.Exists())) // See if we get panics deleting an already deleted item. last.Delete() secondPath.Delete() - c.Assert(root.Exists(), qt.IsFalse) + qt.Assert(t, qt.IsFalse(root.Exists())) } diff --git a/ltep_test.go b/ltep_test.go index 37300f09..0401379d 100644 --- a/ltep_test.go +++ b/ltep_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/anacrolix/sync" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" . "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/internal/testutil" @@ -19,7 +19,7 @@ const ( ) func countHandler( - c *qt.C, + t *testing.T, wg *sync.WaitGroup, // Name of the endpoint that this handler is for, for logging. handlerName string, @@ -38,7 +38,7 @@ func countHandler( return } name, builtin, err := event.PeerConn.LocalLtepProtocolMap.LookupId(event.ExtensionNumber) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) // Not a user protocol. if builtin { return @@ -46,29 +46,27 @@ func countHandler( switch name { case answerToName: u64, err := strconv.ParseUint(string(event.Payload), 10, 0) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) i := uint(u64) - c.Logf("%v got %d", handlerName, i) + t.Logf("%v got %d", handlerName, i) if i == doneValue { wg.Done() return } - c.Assert(i%2, qt.Equals, expectedMod2) + qt.Assert(t, qt.Equals(i%2, expectedMod2)) go func() { - c.Assert( + qt.Assert(t, qt.IsNil( event.PeerConn.WriteExtendedMessage( replyToName, - []byte(strconv.FormatUint(uint64(i+1), 10))), - qt.IsNil) + []byte(strconv.FormatUint(uint64(i+1), 10))))) }() default: - c.Fatalf("got unexpected extension name %q", name) + t.Fatalf("got unexpected extension name %q", name) } } } func TestUserLtep(t *testing.T) { - c := qt.New(t) var wg sync.WaitGroup makeCfg := func() *ClientConfig { @@ -85,33 +83,33 @@ func TestUserLtep(t *testing.T) { // separate goroutine. go func() { // Check sending an extended message for a protocol the peer doesn't support is an error. - c.Check(pc.WriteExtendedMessage("pm_me_floats", []byte("3.142")), qt.IsNotNil) + qt.Check(t, qt.IsNotNil(pc.WriteExtendedMessage("pm_me_floats", []byte("3.142")))) // Kick things off by sending a 1. - c.Check(pc.WriteExtendedMessage(testRepliesToOddsExtensionName, []byte("1")), qt.IsNil) + qt.Check(t, qt.IsNil(pc.WriteExtendedMessage(testRepliesToOddsExtensionName, []byte("1")))) }() } evensCfg.Callbacks.PeerConnReadExtensionMessage = append( evensCfg.Callbacks.PeerConnReadExtensionMessage, - countHandler(c, &wg, "evens", 0, testRepliesToEvensExtensionName, testRepliesToOddsExtensionName, 100)) + countHandler(t, &wg, "evens", 0, testRepliesToEvensExtensionName, testRepliesToOddsExtensionName, 100)) evensCfg.Callbacks.PeerConnAdded = append(evensCfg.Callbacks.PeerConnAdded, func(conn *PeerConn) { conn.LocalLtepProtocolMap.AddUserProtocol(testRepliesToEvensExtensionName) - c.Assert(conn.LocalLtepProtocolMap.Index[conn.LocalLtepProtocolMap.NumBuiltin:], qt.HasLen, 1) + qt.Assert(t, qt.HasLen(conn.LocalLtepProtocolMap.Index[conn.LocalLtepProtocolMap.NumBuiltin:], 1)) }) oddsCfg := makeCfg() oddsCfg.Callbacks.PeerConnAdded = append(oddsCfg.Callbacks.PeerConnAdded, func(conn *PeerConn) { conn.LocalLtepProtocolMap.AddUserProtocol(testRepliesToOddsExtensionName) - c.Assert(conn.LocalLtepProtocolMap.Index[conn.LocalLtepProtocolMap.NumBuiltin:], qt.HasLen, 1) + qt.Assert(t, qt.HasLen(conn.LocalLtepProtocolMap.Index[conn.LocalLtepProtocolMap.NumBuiltin:], 1)) }) oddsCfg.Callbacks.PeerConnReadExtensionMessage = append( oddsCfg.Callbacks.PeerConnReadExtensionMessage, - countHandler(c, &wg, "odds", 1, testRepliesToOddsExtensionName, testRepliesToEvensExtensionName, 100)) + countHandler(t, &wg, "odds", 1, testRepliesToOddsExtensionName, testRepliesToEvensExtensionName, 100)) cl1, err := NewClient(oddsCfg) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer cl1.Close() cl2, err := NewClient(evensCfg) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer cl2.Close() addOpts := AddTorrentOpts{} rand.Read(addOpts.InfoHash[:]) @@ -123,7 +121,7 @@ func TestUserLtep(t *testing.T) { wg.Add(1) added := t1.AddClientPeer(cl2) // Ensure some addresses for the other client were added. - c.Assert(added, qt.Not(qt.Equals), 0) + qt.Assert(t, qt.Not(qt.Equals(added, 0))) wg.Wait() _ = t2 } diff --git a/metainfo/magnet-v2_test.go b/metainfo/magnet-v2_test.go index 620d385c..8011c02e 100644 --- a/metainfo/magnet-v2_test.go +++ b/metainfo/magnet-v2_test.go @@ -3,36 +3,35 @@ package metainfo import ( "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestParseMagnetV2(t *testing.T) { - c := qt.New(t) const v2Only = "magnet:?xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e&dn=bittorrent-v2-test" m2, err := ParseMagnetV2Uri(v2Only) - c.Assert(err, qt.IsNil) - c.Check(m2.InfoHash.Ok, qt.IsFalse) - c.Check(m2.V2InfoHash.Ok, qt.IsTrue) - c.Check(m2.V2InfoHash.Value.HexString(), qt.Equals, "caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e") - c.Check(m2.Params, qt.HasLen, 0) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.IsFalse(m2.InfoHash.Ok)) + qt.Check(t, qt.IsTrue(m2.V2InfoHash.Ok)) + qt.Check(t, qt.Equals(m2.V2InfoHash.Value.HexString(), "caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e")) + qt.Check(t, qt.HasLen(m2.Params, 0)) _, err = ParseMagnetUri(v2Only) - c.Check(err, qt.IsNotNil) + qt.Check(t, qt.IsNotNil(err)) const hybrid = "magnet:?xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&xt=urn:btmh:1220d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb&dn=bittorrent-v1-v2-hybrid-test" m2, err = ParseMagnetV2Uri(hybrid) - c.Assert(err, qt.IsNil) - c.Check(m2.InfoHash.Ok, qt.IsTrue) - c.Check(m2.InfoHash.Value.HexString(), qt.Equals, "631a31dd0a46257d5078c0dee4e66e26f73e42ac") - c.Check(m2.V2InfoHash.Ok, qt.IsTrue) - c.Check(m2.V2InfoHash.Value.HexString(), qt.Equals, "d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb") - c.Check(m2.Params, qt.HasLen, 0) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.IsTrue(m2.InfoHash.Ok)) + qt.Check(t, qt.Equals(m2.InfoHash.Value.HexString(), "631a31dd0a46257d5078c0dee4e66e26f73e42ac")) + qt.Check(t, qt.IsTrue(m2.V2InfoHash.Ok)) + qt.Check(t, qt.Equals(m2.V2InfoHash.Value.HexString(), "d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb")) + qt.Check(t, qt.HasLen(m2.Params, 0)) m, err := ParseMagnetUri(hybrid) - c.Assert(err, qt.IsNil) - c.Check(m.InfoHash.HexString(), qt.Equals, "631a31dd0a46257d5078c0dee4e66e26f73e42ac") - c.Check(m.Params["xt"], qt.HasLen, 1) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.Equals(m.InfoHash.HexString(), "631a31dd0a46257d5078c0dee4e66e26f73e42ac")) + qt.Check(t, qt.HasLen(m.Params["xt"], 1)) } diff --git a/metainfo/magnet_test.go b/metainfo/magnet_test.go index 25475098..0dbd38f2 100644 --- a/metainfo/magnet_test.go +++ b/metainfo/magnet_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/davecgh/go-spew/spew" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -118,18 +118,17 @@ func contains(haystack []string, needle string) bool { // Check that we can parse the magnet link generated from a real-world torrent. This was added due // to a regression in copyParams. func TestParseSintelMagnet(t *testing.T) { - c := qt.New(t) mi, err := LoadFromFile("../testdata/sintel.torrent") - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) m := mi.Magnet(nil, nil) ms := m.String() t.Logf("magnet link: %q", ms) m, err = ParseMagnetUri(ms) - c.Check(err, qt.IsNil) + qt.Check(t, qt.IsNil(err)) spewCfg := spew.NewDefaultConfig() spewCfg.DisableMethods = true spewCfg.Dump(m) m2, err := ParseMagnetV2Uri(ms) spewCfg.Dump(m2) - c.Check(err, qt.IsNil) + qt.Check(t, qt.IsNil(err)) } diff --git a/metainfo/metainfo_test.go b/metainfo/metainfo_test.go index 6a97f911..63644a9f 100644 --- a/metainfo/metainfo_test.go +++ b/metainfo/metainfo_test.go @@ -10,7 +10,7 @@ import ( "github.com/anacrolix/missinggo/v2" "github.com/davecgh/go-spew/spew" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -49,8 +49,7 @@ func TestFile(t *testing.T) { testFile(t, "testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent") testFile(t, "testdata/trackerless.torrent") _, err := LoadFromFile("testdata/minimal-trailing-newline.torrent") - c := qt.New(t) - c.Check(err, qt.ErrorMatches, ".*expected EOF") + qt.Check(t, qt.ErrorMatches(err, ".*expected EOF")) } // Ensure that the correct number of pieces are generated when hashing files. @@ -124,7 +123,7 @@ func TestMetainfoWithListURLList(t *testing.T) { mi, err := LoadFromFile("testdata/SKODAOCTAVIA336x280_archive.torrent") require.NoError(t, err) assert.Len(t, mi.UrlList, 3) - qt.Assert(t, mi.Magnet(nil, nil).String(), qt.ContentEquals, + qt.Assert(t, qt.ContentEquals(mi.Magnet(nil, nil).String(), strings.Join([]string{ "magnet:?xt=urn:btih:d4b197dff199aad447a9a352e31528adbbd97922", "tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce", @@ -132,20 +131,20 @@ func TestMetainfoWithListURLList(t *testing.T) { "ws=https%3A%2F%2Farchive.org%2Fdownload%2F", "ws=http%3A%2F%2Fia601600.us.archive.org%2F26%2Fitems%2F", "ws=http%3A%2F%2Fia801600.us.archive.org%2F26%2Fitems%2F", - }, "&")) + }, "&"))) } func TestMetainfoWithStringURLList(t *testing.T) { mi, err := LoadFromFile("testdata/flat-url-list.torrent") require.NoError(t, err) assert.Len(t, mi.UrlList, 1) - qt.Assert(t, mi.Magnet(nil, nil).String(), qt.ContentEquals, + qt.Assert(t, qt.ContentEquals(mi.Magnet(nil, nil).String(), strings.Join([]string{ "magnet:?xt=urn:btih:9da24e606e4ed9c7b91c1772fb5bf98f82bd9687", "tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce", "tr=http%3A%2F%2Fbt2.archive.org%3A6969%2Fannounce", "ws=https%3A%2F%2Farchive.org%2Fdownload%2F", - }, "&")) + }, "&"))) } // https://github.com/anacrolix/torrent/issues/247 @@ -160,19 +159,17 @@ func TestStringCreationDate(t *testing.T) { // See https://github.com/anacrolix/torrent/issues/843. func TestUnmarshalEmptyStringNodes(t *testing.T) { var mi MetaInfo - c := qt.New(t) err := bencode.Unmarshal([]byte("d5:nodes0:e"), &mi) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) } func TestUnmarshalV2Metainfo(t *testing.T) { - c := qt.New(t) mi, err := LoadFromFile("../testdata/bittorrent-v2-test.torrent") - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) info, err := mi.UnmarshalInfo() - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) spew.Dump(info) - c.Check(info.NumPieces(), qt.Not(qt.Equals), 0) + qt.Check(t, qt.Not(qt.Equals(info.NumPieces(), 0))) err = ValidatePieceLayers(mi.PieceLayers, &info.FileTree, info.PieceLength) - c.Check(err, qt.IsNil) + qt.Check(t, qt.IsNil(err)) } diff --git a/peer_protocol/decoder_test.go b/peer_protocol/decoder_test.go index 39b54c1c..d03927ac 100644 --- a/peer_protocol/decoder_test.go +++ b/peer_protocol/decoder_test.go @@ -7,7 +7,7 @@ import ( "sync" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -35,7 +35,6 @@ func BenchmarkDecodePieces(t *testing.B) { }, }, } - c := qt.New(t) t.ReportAllocs() t.ResetTimer() for i := 0; i < t.N; i += 1 { @@ -47,7 +46,7 @@ func BenchmarkDecodePieces(t *testing.B) { } // This is very expensive, and should be discovered in tests rather than a benchmark. if false { - c.Assert(msg, qt.DeepEquals, inputMsg) + qt.Assert(t, qt.DeepEquals(msg, inputMsg)) } // WWJD d.Pool.Put(&msg.Piece) diff --git a/peer_protocol/fuzz_test.go b/peer_protocol/fuzz_test.go index 8ffdfd7b..dbf54f3c 100644 --- a/peer_protocol/fuzz_test.go +++ b/peer_protocol/fuzz_test.go @@ -9,7 +9,7 @@ import ( "io" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func FuzzDecoder(f *testing.F) { @@ -19,7 +19,6 @@ func FuzzDecoder(f *testing.F) { f.Add([]byte("\x00\x00\x00\x01\x07")) f.Fuzz(func(t *testing.T, b []byte) { t.Logf("%q", b) - c := qt.New(t) d := Decoder{ R: bufio.NewReader(bytes.NewReader(b)), MaxLength: 0x100, @@ -33,7 +32,7 @@ func FuzzDecoder(f *testing.F) { break } if err == nil { - c.Assert(m, qt.Not(qt.Equals), Message{}) + qt.Assert(t, qt.Not(qt.Equals(m, Message{}))) ms = append(ms, m) continue } else { @@ -46,9 +45,9 @@ func FuzzDecoder(f *testing.F) { buf.Write(m.MustMarshalBinary()) } if len(b) == 0 { - c.Assert(buf.Bytes(), qt.HasLen, 0) + qt.Assert(t, qt.HasLen(buf.Bytes(), 0)) } else { - c.Assert(buf.Bytes(), qt.DeepEquals, b) + qt.Assert(t, qt.DeepEquals(buf.Bytes(), b)) } }) } @@ -60,6 +59,6 @@ func FuzzMessageMarshalBinary(f *testing.F) { t.Skip(err) } b0 := m.MustMarshalBinary() - qt.Assert(t, b0, qt.DeepEquals, b) + qt.Assert(t, qt.DeepEquals(b0, b)) }) } diff --git a/peer_protocol/reserved_test.go b/peer_protocol/reserved_test.go index 53f9d86d..178703fb 100644 --- a/peer_protocol/reserved_test.go +++ b/peer_protocol/reserved_test.go @@ -3,12 +3,11 @@ package peer_protocol import ( "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestV2BitLocation(t *testing.T) { var bits PeerExtensionBits bits.SetBit(ExtensionBitV2Upgrade, true) - c := qt.New(t) - c.Assert(bits[7], qt.Equals, byte(0x10)) + qt.Assert(t, qt.Equals(bits[7], byte(0x10))) } diff --git a/peer_protocol/ut-holepunch/ut-holepunch_test.go b/peer_protocol/ut-holepunch/ut-holepunch_test.go index 7221e1f7..7177d709 100644 --- a/peer_protocol/ut-holepunch/ut-holepunch_test.go +++ b/peer_protocol/ut-holepunch/ut-holepunch_test.go @@ -5,7 +5,7 @@ import ( "net/netip" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) var exampleMsgs = []Msg{ @@ -22,19 +22,18 @@ var exampleMsgs = []Msg{ } func TestUnmarshalMsg(t *testing.T) { - c := qt.New(t) for _, m := range exampleMsgs { b, err := m.MarshalBinary() - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) expectedLen := 24 if m.AddrPort.Addr().Is4() { expectedLen = 12 } - c.Check(b, qt.HasLen, expectedLen) + qt.Check(t, qt.HasLen(b, expectedLen)) var um Msg err = um.UnmarshalBinary(b) - c.Assert(err, qt.IsNil) - c.Check(um, qt.Equals, m) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.Equals(um, m)) } } diff --git a/request-strategy-impls_test.go b/request-strategy-impls_test.go index 3940da0e..6bcd9981 100644 --- a/request-strategy-impls_test.go +++ b/request-strategy-impls_test.go @@ -9,7 +9,7 @@ import ( g "github.com/anacrolix/generics" "github.com/anacrolix/missinggo/v2/iter" "github.com/davecgh/go-spew/spew" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/anacrolix/torrent/metainfo" request_strategy "github.com/anacrolix/torrent/request-strategy" @@ -22,14 +22,13 @@ func makeRequestStrategyPiece(t request_strategy.Torrent) request_strategy.Piece } func TestRequestStrategyPieceDoesntAlloc(t *testing.T) { - c := qt.New(t) akshalTorrent := &Torrent{pieces: make([]Piece, 1)} rst := requestStrategyTorrent{akshalTorrent} var before, after runtime.MemStats runtime.ReadMemStats(&before) p := makeRequestStrategyPiece(rst) runtime.ReadMemStats(&after) - c.Assert(before.HeapAlloc, qt.Equals, after.HeapAlloc) + qt.Assert(t, qt.Equals(before.HeapAlloc, after.HeapAlloc)) // We have to use p, or it gets optimized away. spew.Fdump(io.Discard, p) } @@ -81,7 +80,6 @@ func (s *storageClient) OpenTorrent( } func BenchmarkRequestStrategy(b *testing.B) { - c := qt.New(b) cl := newTestingClient(b) storageClient := storageClient{} tor, new := cl.AddTorrentOpt(AddTorrentOpts{ @@ -89,7 +87,7 @@ func BenchmarkRequestStrategy(b *testing.B) { Storage: &storageClient, }) tor.disableTriggers = true - c.Assert(new, qt.IsTrue) + qt.Assert(b, qt.IsTrue(new)) const pieceLength = 1 << 8 << 10 const numPieces = 30_000 err := tor.setInfo(&metainfo.Info{ @@ -97,13 +95,13 @@ func BenchmarkRequestStrategy(b *testing.B) { PieceLength: pieceLength, Length: pieceLength * numPieces, }) - c.Assert(err, qt.IsNil) + qt.Assert(b, qt.IsNil(err)) tor.onSetInfo() peer := cl.newConnection(nil, newConnectionOpts{ network: "test", }) peer.setTorrent(tor) - c.Assert(tor.storage, qt.IsNotNil) + qt.Assert(b, qt.IsNotNil(tor.storage)) const chunkSize = defaultChunkSize peer.onPeerHasAllPiecesNoTriggers() for i := 0; i < tor.numPieces(); i++ { @@ -129,9 +127,9 @@ func BenchmarkRequestStrategy(b *testing.B) { tor.cacheNextRequestIndexesForReuse(rs.Requests.requestIndexes) // End of part that should be timed. remainingChunks := (numPieces - completed) * (pieceLength / chunkSize) - c.Assert(rs.Requests.requestIndexes, qt.HasLen, min( + qt.Assert(b, qt.HasLen(rs.Requests.requestIndexes, min( remainingChunks, - int(cl.config.MaxUnverifiedBytes/chunkSize))) + int(cl.config.MaxUnverifiedBytes/chunkSize)))) } } } diff --git a/requesting_test.go b/requesting_test.go index 6c791a58..385b71f2 100644 --- a/requesting_test.go +++ b/requesting_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/bradfitz/iter" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" pp "github.com/anacrolix/torrent/peer_protocol" ) @@ -35,12 +35,12 @@ func TestLogExampleRequestMapOrdering(t *testing.T) { func TestRequestMapOrderingPersistent(t *testing.T) { m := makeTypicalRequests() // Shows that map order is persistent across separate range statements. - qt.Assert(t, keysAsSlice(m), qt.ContentEquals, keysAsSlice(m)) + qt.Assert(t, qt.ContentEquals(keysAsSlice(m), keysAsSlice(m))) } func TestRequestMapOrderAcrossInstances(t *testing.T) { // This shows that different map instances with the same contents can have the same range order. - qt.Assert(t, keysAsSlice(makeTypicalRequests()), qt.ContentEquals, keysAsSlice(makeTypicalRequests())) + qt.Assert(t, qt.ContentEquals(keysAsSlice(makeTypicalRequests()), keysAsSlice(makeTypicalRequests()))) } // Added for testing repeating loop iteration after shuffling in Peer.applyRequestState. @@ -58,7 +58,7 @@ func TestForLoopRepeatItem(t *testing.T) { } } // We can mutate i and it's observed by the loop. No special treatment of the loop var. - qt.Assert(t, seen, qt.DeepEquals, []int{0, 1, 2, 2, 3}) + qt.Assert(t, qt.DeepEquals(seen, []int{0, 1, 2, 2, 3})) }) t.Run("Range", func(t *testing.T) { once := false @@ -73,6 +73,6 @@ func TestForLoopRepeatItem(t *testing.T) { } } // Range ignores any mutation to i. - qt.Assert(t, seen, qt.DeepEquals, []int{0, 1, 2, 3}) + qt.Assert(t, qt.DeepEquals(seen, []int{0, 1, 2, 3})) }) } diff --git a/reuse_test.go b/reuse_test.go index 5da4ab80..711920dd 100644 --- a/reuse_test.go +++ b/reuse_test.go @@ -8,14 +8,13 @@ import ( "testing" "github.com/anacrolix/log" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) // Show that multiple connections from the same local TCP port to the same remote port will fail. func TestTcpPortReuseIsABadIdea(t *testing.T) { remote, err := net.Listen("tcp", "localhost:0") - c := qt.New(t) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer remote.Close() dialer := net.Dialer{} // Show that we can't duplicate an existing connection even with various socket options. @@ -26,16 +25,16 @@ func TestTcpPortReuseIsABadIdea(t *testing.T) { } // Tie up a local port to the remote. first, err := dialer.Dial("tcp", remote.Addr().String()) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer first.Close() // Show that dialling the remote with the same local port fails. dialer.LocalAddr = first.LocalAddr() _, err = dialer.Dial("tcp", remote.Addr().String()) - c.Assert(err, qt.IsNotNil) + qt.Assert(t, qt.IsNotNil(err)) // Show that not fixing the local port again allows connections to succeed. dialer.LocalAddr = nil second, err := dialer.Dial("tcp", remote.Addr().String()) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) second.Close() } @@ -43,9 +42,8 @@ func TestTcpPortReuseIsABadIdea(t *testing.T) { // succeed. This is necessary for ut_holepunch to work. func TestUtpLocalPortIsReusable(t *testing.T) { const network = "udp" - c := qt.New(t) remote, err := NewUtpSocket(network, "localhost:0", nil, log.Default) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer remote.Close() var remoteAccepts int32 doneAccepting := make(chan struct{}) @@ -65,15 +63,15 @@ func TestUtpLocalPortIsReusable(t *testing.T) { } }() local, err := NewUtpSocket(network, "localhost:0", nil, log.Default) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer local.Close() first, err := local.DialContext(context.Background(), network, remote.Addr().String()) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer first.Close() second, err := local.DialContext(context.Background(), network, remote.Addr().String()) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer second.Close() remote.Close() <-doneAccepting - c.Assert(atomic.LoadInt32(&remoteAccepts), qt.Equals, int32(2)) + qt.Assert(t, qt.Equals(atomic.LoadInt32(&remoteAccepts), int32(2))) } diff --git a/segments/segments_test.go b/segments/segments_test.go index c8c45376..1620f77b 100644 --- a/segments/segments_test.go +++ b/segments/segments_test.go @@ -3,7 +3,7 @@ package segments import ( "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func LengthIterFromSlice(ls []Length) LengthIter { @@ -50,7 +50,7 @@ func checkContiguous( expected.scanCallback(firstExpectedIndex+i, e) } nl(LengthIterFromSlice(ls))(needle, actual.scanCallback) - qt.Check(t, actual, qt.DeepEquals, expected) + qt.Check(t, qt.DeepEquals(actual, expected)) } func testLocater(t *testing.T, newLocater newLocater) { diff --git a/storage/mark-complete_test.go b/storage/mark-complete_test.go index 843a609a..0deb1959 100644 --- a/storage/mark-complete_test.go +++ b/storage/mark-complete_test.go @@ -4,6 +4,7 @@ import ( "testing" g "github.com/anacrolix/generics" + "github.com/anacrolix/torrent/storage" test_storage "github.com/anacrolix/torrent/storage/test" ) diff --git a/test/leecher-storage.go b/test/leecher-storage.go index dfaad2bc..edd62eba 100644 --- a/test/leecher-storage.go +++ b/test/leecher-storage.go @@ -9,7 +9,7 @@ import ( "testing/iotest" "github.com/anacrolix/missinggo/v2/bitmap" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/time/rate" @@ -97,7 +97,7 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) { newGOMAXPROCS = ps.GOMAXPROCS } defer func() { - qt.Check(t, runtime.GOMAXPROCS(prevGOMAXPROCS), qt.ContentEquals, newGOMAXPROCS) + qt.Check(t, qt.ContentEquals(runtime.GOMAXPROCS(prevGOMAXPROCS), newGOMAXPROCS)) }() greetingTempDir, mi := testutil.GreetingTestTorrent() @@ -251,5 +251,5 @@ func assertReadAllGreeting(t *testing.T, r io.ReadSeeker) { pos, err := r.Seek(0, io.SeekStart) assert.NoError(t, err) assert.EqualValues(t, 0, pos) - qt.Check(t, iotest.TestReader(r, []byte(testutil.GreetingFileContents)), qt.IsNil) + qt.Check(t, qt.IsNil(iotest.TestReader(r, []byte(testutil.GreetingFileContents)))) } diff --git a/test/sqlite_test.go b/test/sqlite_test.go index 36da82f8..7d4b915a 100644 --- a/test/sqlite_test.go +++ b/test/sqlite_test.go @@ -12,7 +12,7 @@ import ( "net/http" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/bencode" @@ -21,18 +21,17 @@ import ( ) func TestSqliteStorageClosed(t *testing.T) { - c := qt.New(t) cfg := torrent.TestingConfig(t) storage, err := sqliteStorage.NewDirectStorage(sqliteStorage.NewDirectStorageOpts{}) defer storage.Close() cfg.DefaultStorage = storage cfg.Debug = true - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) cl, err := torrent.NewClient(cfg) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer cl.Close() l, err := net.Listen("tcp", "localhost:0") - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer l.Close() // We need at least once piece to trigger a call to storage to determine completion state. We // need non-zero content length to trigger piece hashing. @@ -45,7 +44,7 @@ func TestSqliteStorageClosed(t *testing.T) { } mi := metainfo.MetaInfo{} mi.InfoBytes, err = bencode.Marshal(i) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) s := http.Server{ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mi.Write(w) @@ -64,6 +63,6 @@ func TestSqliteStorageClosed(t *testing.T) { InfoHash: mi.HashInfoBytes(), }) tor.AddSources([]string{"http://" + l.Addr().String()}) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) <-tor.GotInfo() } diff --git a/test/transfer_test.go b/test/transfer_test.go index 6d3e460b..5241db3b 100644 --- a/test/transfer_test.go +++ b/test/transfer_test.go @@ -10,7 +10,7 @@ import ( "github.com/anacrolix/log" "github.com/anacrolix/missinggo/v2/filecache" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/time/rate" @@ -207,7 +207,7 @@ func testSeedAfterDownloading(t *testing.T, disableUtp bool) { go func() { defer wg.Done() defer r.Close() - qt.Check(t, iotest.TestReader(r, []byte(testutil.GreetingFileContents)), qt.IsNil) + qt.Check(t, qt.IsNil(iotest.TestReader(r, []byte(testutil.GreetingFileContents)))) }() } go leecherGreeting.AddClientPeer(seeder) diff --git a/tests/add-webseed-after-priorities/go.mod b/tests/add-webseed-after-priorities/go.mod index 98e28918..e5eaf257 100644 --- a/tests/add-webseed-after-priorities/go.mod +++ b/tests/add-webseed-after-priorities/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( github.com/anacrolix/torrent v1.56.1 - github.com/frankban/quicktest v1.14.6 + github.com/go-quicktest/qt v1.101.0 ) require ( diff --git a/tests/add-webseed-after-priorities/herp_test.go b/tests/add-webseed-after-priorities/herp_test.go index 6c89a87b..8c4bad2c 100644 --- a/tests/add-webseed-after-priorities/herp_test.go +++ b/tests/add-webseed-after-priorities/herp_test.go @@ -3,7 +3,7 @@ package webseed_partial_seed import ( "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/internal/testutil" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "path/filepath" "runtime" "testing" @@ -50,7 +50,6 @@ func downloadAll(t *torrent.Torrent) { } func TestWebseedPartialSeed(t *testing.T) { - c := qt.New(t) seederClient := makeSeederClient(t) defer seederClient.Close() testutil.ExportStatusWriter(seederClient, "seeder", t) @@ -82,5 +81,5 @@ func TestWebseedPartialSeed(t *testing.T) { time.Sleep(time.Second) seederTorrent.AddWebSeeds([]string{"http://localhost:3003/test.img"}) allDownloaded := leecherClient.WaitAll() - c.Assert(allDownloaded, qt.IsTrue) + qt.Assert(t, qt.IsTrue(allDownloaded)) } diff --git a/tests/issue-952/issue-952_test.go b/tests/issue-952/issue-952_test.go index 82206477..54f53d06 100644 --- a/tests/issue-952/issue-952_test.go +++ b/tests/issue-952/issue-952_test.go @@ -3,7 +3,7 @@ package issue_952 import ( "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/metainfo" @@ -25,16 +25,15 @@ func TestUnmarshalStringToByteArray(t *testing.T) { var s scrapeResponse const hashStr = "\x05a~F\xfd{c\xd1`\xb8\xd9\x89\xceM\xb9t\x1d\\\x0b\xded" err := bencode.Unmarshal([]byte("d5:filesd20:\x05a~F\xfd{c\xd1`\xb8\xd9\x89\xceM\xb9t\x1d\\\x0b\xded9:completedi1e10:downloadedi1eeee"), &s) - c := qt.New(t) - c.Assert(err, qt.IsNil) - c.Check(s.Files, qt.HasLen, 1) + qt.Assert(t, qt.IsNil(err)) + qt.Check(t, qt.HasLen(s.Files, 1)) file, ok := s.Files[(infohash.T)([]byte(hashStr))] - c.Assert(ok, qt.IsTrue) - c.Check(file, qt.Equals, scrapeResponseFile{ + qt.Assert(t, qt.IsTrue(ok)) + qt.Check(t, qt.Equals(file, scrapeResponseFile{ // Note that complete is misspelled in the example. I don't know why. Complete: 0, Downloaded: 1, Incomplete: 0, - }) + })) } diff --git a/tests/webseed-partial-seed/go.mod b/tests/webseed-partial-seed/go.mod index 98e28918..e5eaf257 100644 --- a/tests/webseed-partial-seed/go.mod +++ b/tests/webseed-partial-seed/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( github.com/anacrolix/torrent v1.56.1 - github.com/frankban/quicktest v1.14.6 + github.com/go-quicktest/qt v1.101.0 ) require ( diff --git a/tests/webseed-partial-seed/herp_test.go b/tests/webseed-partial-seed/herp_test.go index 8eedff36..872775ff 100644 --- a/tests/webseed-partial-seed/herp_test.go +++ b/tests/webseed-partial-seed/herp_test.go @@ -7,7 +7,7 @@ import ( "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/internal/testutil" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func testSrcDir() string { @@ -50,7 +50,6 @@ func downloadAll(t *torrent.Torrent) { } func TestWebseedPartialSeed(t *testing.T) { - c := qt.New(t) seederClient := makeSeederClient(t) defer seederClient.Close() testutil.ExportStatusWriter(seederClient, "seeder", t) @@ -79,5 +78,5 @@ func TestWebseedPartialSeed(t *testing.T) { seederTorrent.DownloadAll() allDownloaded := leecherClient.WaitAll() - c.Assert(allDownloaded, qt.IsTrue) + qt.Assert(t, qt.IsTrue(allDownloaded)) } diff --git a/ut-holepunching_test.go b/ut-holepunching_test.go index 591f3760..519b72bc 100644 --- a/ut-holepunching_test.go +++ b/ut-holepunching_test.go @@ -15,7 +15,7 @@ import ( "github.com/anacrolix/log" "github.com/anacrolix/missinggo/v2/iter" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/time/rate" @@ -26,7 +26,6 @@ import ( // Check that after completing leeching, a leecher transitions to a seeding // correctly. Connected in a chain like so: Seeder <-> Leecher <-> LeecherLeecher. func TestHolepunchConnect(t *testing.T) { - c := qt.New(t) greetingTempDir, mi := testutil.GreetingTestTorrent() defer os.RemoveAll(greetingTempDir) @@ -101,7 +100,7 @@ func TestHolepunchConnect(t *testing.T) { defer wg.Done() r := llg.NewReader() defer r.Close() - qt.Check(t, iotest.TestReader(r, []byte(testutil.GreetingFileContents)), qt.IsNil) + qt.Check(t, qt.IsNil(iotest.TestReader(r, []byte(testutil.GreetingFileContents)))) }() go seederTorrent.AddClientPeer(leecher) waitForConns(seederTorrent) @@ -123,13 +122,13 @@ func TestHolepunchConnect(t *testing.T) { llg.cl.unlock() wg.Wait() - c.Check(seeder.dialedSuccessfullyAfterHolepunchConnect, qt.Not(qt.HasLen), 0) - c.Check(leecherLeecher.probablyOnlyConnectedDueToHolepunch, qt.Not(qt.HasLen), 0) + qt.Check(t, qt.Not(qt.HasLen(seeder.dialedSuccessfullyAfterHolepunchConnect, 0))) + qt.Check(t, qt.Not(qt.HasLen(leecherLeecher.probablyOnlyConnectedDueToHolepunch, 0))) llClientStats := leecherLeecher.Stats() - c.Check(llClientStats.NumPeersUndialableWithoutHolepunch, qt.Not(qt.Equals), 0) - c.Check(llClientStats.NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect, qt.Not(qt.Equals), 0) - c.Check(llClientStats.NumPeersProbablyOnlyConnectedDueToHolepunch, qt.Not(qt.Equals), 0) + qt.Check(t, qt.Not(qt.Equals(llClientStats.NumPeersUndialableWithoutHolepunch, 0))) + qt.Check(t, qt.Not(qt.Equals(llClientStats.NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect, 0))) + qt.Check(t, qt.Not(qt.Equals(llClientStats.NumPeersProbablyOnlyConnectedDueToHolepunch, 0))) } func waitForConns(t *Torrent) { @@ -146,11 +145,10 @@ func waitForConns(t *Torrent) { // Show that dialling TCP will complete before the other side accepts. func TestDialTcpNotAccepting(t *testing.T) { l, err := net.Listen("tcp", "localhost:0") - c := qt.New(t) - c.Check(err, qt.IsNil) + qt.Check(t, qt.IsNil(err)) defer l.Close() dialedConn, err := net.Dial("tcp", l.Addr().String()) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) dialedConn.Close() } @@ -168,14 +166,13 @@ func TestTcpSimultaneousOpen(t *testing.T) { return dialer.DialContext(ctx, network, remoteAddr) } } - c := qt.New(t) // I really hate doing this in unit tests, but we would need to pick apart Dialer to get // perfectly synchronized simultaneous dials. for range iter.N(10) { first, second := randPortPair() t.Logf("ports are %v and %v", first, second) err := testSimultaneousOpen( - c.Cleanup, + t.Cleanup, makeDialer(first, fmt.Sprintf("localhost:%d", second)), makeDialer(second, fmt.Sprintf("localhost:%d", first)), ) @@ -311,7 +308,6 @@ const defaultMsg = "hello" // for one or both peers involved. func TestUtpSimultaneousOpen(t *testing.T) { t.Parallel() - c := qt.New(t) const network = "udp" ctx := context.Background() newUtpSocket := func(addr string) utpSocket { @@ -323,7 +319,7 @@ func TestUtpSimultaneousOpen(t *testing.T) { }, log.Default, ) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) return socket } first := newUtpSocket("localhost:0") @@ -338,7 +334,7 @@ func TestUtpSimultaneousOpen(t *testing.T) { t.Logf("first addr is %v. second addr is %v", first.Addr().String(), second.Addr().String()) for range iter.N(10) { err := testSimultaneousOpen( - c.Cleanup, + t.Cleanup, getDial(first, second.Addr().String()), getDial(second, first.Addr().String()), ) @@ -370,14 +366,13 @@ func skipGoUtpDialIssue(t *testing.T, err error) { // same connection. func TestUtpDirectDialMsg(t *testing.T) { t.Parallel() - c := qt.New(t) const network = "udp4" ctx := context.Background() newUtpSocket := func(addr string) utpSocket { socket, err := NewUtpSocket(network, addr, func(net.Addr) bool { return false }, log.Default) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) return socket } for range iter.N(10) { @@ -392,7 +387,7 @@ func TestUtpDirectDialMsg(t *testing.T) { } defer writer.Close() reader, err := second.Accept() - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer reader.Close() return writeAndReadMsg(reader, writer) }() diff --git a/webseed-peer.go b/webseed-peer.go index d08f9821..5de29d77 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -13,6 +13,7 @@ import ( "github.com/RoaringBitmap/roaring" g "github.com/anacrolix/generics" "github.com/anacrolix/missinggo/v2/panicif" + "github.com/anacrolix/torrent/metainfo" pp "github.com/anacrolix/torrent/peer_protocol" "github.com/anacrolix/torrent/webseed" diff --git a/webseed/request_test.go b/webseed/request_test.go index af3071f3..567db3a4 100644 --- a/webseed/request_test.go +++ b/webseed/request_test.go @@ -4,13 +4,12 @@ import ( "net/url" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestDefaultPathEscaper(t *testing.T) { - c := qt.New(t) test := func(unescaped string, parts ...string) { - assertPartsUnescape(c, unescaped, parts...) + assertPartsUnescape(t, unescaped, parts...) } for _, tc := range defaultPathEscapeTestCases { test(tc.escaped, tc.parts...) @@ -36,14 +35,14 @@ var defaultPathEscapeTestCases = []struct { }, } -func assertPartsUnescape(c *qt.C, unescaped string, parts ...string) { +func assertPartsUnescape(t *testing.T, unescaped string, parts ...string) { escaped := defaultPathEscaper(parts) pathUnescaped, err := url.PathUnescape(escaped) - c.Assert(err, qt.IsNil) - c.Assert(pathUnescaped, qt.Equals, unescaped) + qt.Assert(t, qt.IsNil(err)) + qt.Assert(t, qt.Equals(pathUnescaped, unescaped)) queryUnescaped, err := url.QueryUnescape(escaped) - c.Assert(err, qt.IsNil) - c.Assert(queryUnescaped, qt.Equals, unescaped) + qt.Assert(t, qt.IsNil(err)) + qt.Assert(t, qt.Equals(queryUnescaped, unescaped)) } func FuzzDefaultPathEscaper(f *testing.F) { @@ -55,6 +54,6 @@ func FuzzDefaultPathEscaper(f *testing.F) { // I think a single separator is enough to test special handling around /. Also fuzzing doesn't // let us take []string as an input. f.Fuzz(func(t *testing.T, first, second string) { - assertPartsUnescape(qt.New(t), first+"/"+second, first, second) + assertPartsUnescape(t, first+"/"+second, first, second) }) } diff --git a/webtorrent/fuzz_test.go b/webtorrent/fuzz_test.go index 14638fa2..8e194d4c 100644 --- a/webtorrent/fuzz_test.go +++ b/webtorrent/fuzz_test.go @@ -7,7 +7,7 @@ import ( "encoding/json" "testing" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func FuzzJsonBinaryStrings(f *testing.F) { @@ -23,9 +23,8 @@ func FuzzJsonBinaryStrings(f *testing.F) { t.Fatal(err) } // t.Logf("%q", jsonStr) - c := qt.New(t) out, err := decodeJsonByteString(jsonStr, []byte{}) - c.Assert(err, qt.IsNil) - c.Assert(out, qt.DeepEquals, in) + qt.Assert(t, qt.IsNil(err)) + qt.Assert(t, qt.DeepEquals(out, in)) }) } diff --git a/webtorrent/transport_test.go b/webtorrent/transport_test.go index 753339d3..9ea1263b 100644 --- a/webtorrent/transport_test.go +++ b/webtorrent/transport_test.go @@ -7,15 +7,14 @@ import ( "testing" "github.com/anacrolix/log" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" "github.com/pion/webrtc/v4" ) func TestClosingPeerConnectionDoesNotCloseUnopenedDataChannel(t *testing.T) { - c := qt.New(t) var tc TrackerClient pc, dc, _, err := tc.newOffer(log.Default, "", [20]byte{}) - c.Assert(err, qt.IsNil) + qt.Assert(t, qt.IsNil(err)) defer pc.Close() defer dc.Close() peerConnClosed := make(chan struct{}) @@ -33,6 +32,6 @@ func TestClosingPeerConnectionDoesNotCloseUnopenedDataChannel(t *testing.T) { t.Logf("data channel error: %v", err) }) pc.Close() - c.Check(dc.ReadyState(), qt.Equals, webrtc.DataChannelStateClosed) + qt.Check(t, qt.Equals(dc.ReadyState(), webrtc.DataChannelStateClosed)) <-peerConnClosed } diff --git a/worse-conns_test.go b/worse-conns_test.go index 3865b648..ad9079ee 100644 --- a/worse-conns_test.go +++ b/worse-conns_test.go @@ -4,41 +4,40 @@ import ( "testing" "time" - qt "github.com/frankban/quicktest" + qt "github.com/go-quicktest/qt" ) func TestWorseConnLastHelpful(t *testing.T) { - c := qt.New(t) - c.Check((&worseConnInput{}).Less(&worseConnInput{LastHelpful: time.Now()}), qt.IsTrue) - c.Check((&worseConnInput{}).Less(&worseConnInput{CompletedHandshake: time.Now()}), qt.IsTrue) - c.Check((&worseConnInput{LastHelpful: time.Now()}).Less(&worseConnInput{CompletedHandshake: time.Now()}), qt.IsFalse) - c.Check((&worseConnInput{ + qt.Check(t, qt.IsTrue((&worseConnInput{}).Less(&worseConnInput{LastHelpful: time.Now()}))) + qt.Check(t, qt.IsTrue((&worseConnInput{}).Less(&worseConnInput{CompletedHandshake: time.Now()}))) + qt.Check(t, qt.IsFalse((&worseConnInput{LastHelpful: time.Now()}).Less(&worseConnInput{CompletedHandshake: time.Now()}))) + qt.Check(t, qt.IsTrue((&worseConnInput{ LastHelpful: time.Now(), }).Less(&worseConnInput{ LastHelpful: time.Now(), CompletedHandshake: time.Now(), - }), qt.IsTrue) + }))) now := time.Now() - c.Check((&worseConnInput{ + qt.Check(t, qt.IsFalse((&worseConnInput{ LastHelpful: now, }).Less(&worseConnInput{ LastHelpful: now.Add(-time.Nanosecond), CompletedHandshake: now, - }), qt.IsFalse) + }))) readyPeerPriority := func() (peerPriority, error) { return 42, nil } - c.Check((&worseConnInput{ + qt.Check(t, qt.IsTrue((&worseConnInput{ GetPeerPriority: readyPeerPriority, }).Less(&worseConnInput{ GetPeerPriority: readyPeerPriority, Pointer: 1, - }), qt.IsTrue) - c.Check((&worseConnInput{ + }))) + qt.Check(t, qt.IsFalse((&worseConnInput{ GetPeerPriority: readyPeerPriority, Pointer: 2, }).Less(&worseConnInput{ GetPeerPriority: readyPeerPriority, Pointer: 1, - }), qt.IsFalse) + }))) } -- 2.51.0