Claude did this. Pretty neat. Only took 18 months of waiting for it to get decent.
import (
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
)
func TestBytesMarshalNil(t *testing.T) {
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 {
}
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")))
}
"strings"
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
}{}
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)
}
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{}
// 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)
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))
}
}
}
// 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
}
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)
"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
+ })))
})
}
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))
})
}
"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) {
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
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
"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))
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))
}
"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()))
}
"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"
)
func countHandler(
- c *qt.C,
+ t *testing.T,
wg *sync.WaitGroup,
// Name of the endpoint that this handler is for, for logging.
handlerName string,
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
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 {
// 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[:])
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
}
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))
}
"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"
)
// 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))
}
"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"
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.
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",
"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
// 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))
}
"sync"
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
},
},
}
- c := qt.New(t)
t.ReportAllocs()
t.ResetTimer()
for i := 0; i < t.N; i += 1 {
}
// 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)
"io"
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
)
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,
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 {
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))
}
})
}
t.Skip(err)
}
b0 := m.MustMarshalBinary()
- qt.Assert(t, b0, qt.DeepEquals, b)
+ qt.Assert(t, qt.DeepEquals(b0, b))
})
}
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)))
}
"net/netip"
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
)
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))
}
}
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"
}
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)
}
}
func BenchmarkRequestStrategy(b *testing.B) {
- c := qt.New(b)
cl := newTestingClient(b)
storageClient := storageClient{}
tor, new := cl.AddTorrentOpt(AddTorrentOpts{
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{
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++ {
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))))
}
}
}
"testing"
"github.com/bradfitz/iter"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
pp "github.com/anacrolix/torrent/peer_protocol"
)
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.
}
}
// 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
}
}
// 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}))
})
}
"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.
}
// 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()
}
// 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{})
}
}()
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)))
}
import (
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
)
func LengthIterFromSlice(ls []Length) LengthIter {
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) {
"testing"
g "github.com/anacrolix/generics"
+
"github.com/anacrolix/torrent/storage"
test_storage "github.com/anacrolix/torrent/storage/test"
)
"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"
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()
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))))
}
"net/http"
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/bencode"
)
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.
}
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)
InfoHash: mi.HashInfoBytes(),
})
tor.AddSources([]string{"http://" + l.Addr().String()})
- c.Assert(err, qt.IsNil)
+ qt.Assert(t, qt.IsNil(err))
<-tor.GotInfo()
}
"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"
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)
require (
github.com/anacrolix/torrent v1.56.1
- github.com/frankban/quicktest v1.14.6
+ github.com/go-quicktest/qt v1.101.0
)
require (
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"
}
func TestWebseedPartialSeed(t *testing.T) {
- c := qt.New(t)
seederClient := makeSeederClient(t)
defer seederClient.Close()
testutil.ExportStatusWriter(seederClient, "seeder", 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))
}
import (
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/metainfo"
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,
- })
+ }))
}
require (
github.com/anacrolix/torrent v1.56.1
- github.com/frankban/quicktest v1.14.6
+ github.com/go-quicktest/qt v1.101.0
)
require (
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/internal/testutil"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
)
func testSrcDir() string {
}
func TestWebseedPartialSeed(t *testing.T) {
- c := qt.New(t)
seederClient := makeSeederClient(t)
defer seederClient.Close()
testutil.ExportStatusWriter(seederClient, "seeder", t)
seederTorrent.DownloadAll()
allDownloaded := leecherClient.WaitAll()
- c.Assert(allDownloaded, qt.IsTrue)
+ qt.Assert(t, qt.IsTrue(allDownloaded))
}
"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"
// 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)
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)
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) {
// 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()
}
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)),
)
// 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 {
},
log.Default,
)
- c.Assert(err, qt.IsNil)
+ qt.Assert(t, qt.IsNil(err))
return socket
}
first := newUtpSocket("localhost:0")
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()),
)
// 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) {
}
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)
}()
"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"
"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...)
},
}
-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) {
// 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)
})
}
"encoding/json"
"testing"
- qt "github.com/frankban/quicktest"
+ qt "github.com/go-quicktest/qt"
)
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))
})
}
"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{})
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
}
"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)
+ })))
}