Skip to content

Commit 81ea056

Browse files
sayboraslmb
authored andcommitted
test: Migrate tests to github.com/go-quicktest/qt
Fixes: #1251 Signed-off-by: Tam Mach <[email protected]>
1 parent e7d0606 commit 81ea056

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+537
-570
lines changed

asm/instruction_test.go

+18-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"math"
1111
"testing"
1212

13-
qt "github.com/frankban/quicktest"
13+
"github.com/go-quicktest/qt"
1414
)
1515

1616
var test64bitImmProg = []byte{
@@ -110,23 +110,23 @@ func TestSignedJump(t *testing.T) {
110110
func TestInstructionRewriteMapConstant(t *testing.T) {
111111
ins := LoadMapValue(R0, 123, 321)
112112

113-
qt.Assert(t, ins.MapPtr(), qt.Equals, 123)
114-
qt.Assert(t, ins.mapOffset(), qt.Equals, uint32(321))
113+
qt.Assert(t, qt.Equals(ins.MapPtr(), 123))
114+
qt.Assert(t, qt.Equals(ins.mapOffset(), 321))
115115

116-
qt.Assert(t, ins.RewriteMapPtr(-1), qt.IsNil)
117-
qt.Assert(t, ins.MapPtr(), qt.Equals, -1)
116+
qt.Assert(t, qt.IsNil(ins.RewriteMapPtr(-1)))
117+
qt.Assert(t, qt.Equals(ins.MapPtr(), -1))
118118

119-
qt.Assert(t, ins.RewriteMapPtr(1), qt.IsNil)
120-
qt.Assert(t, ins.MapPtr(), qt.Equals, 1)
119+
qt.Assert(t, qt.IsNil(ins.RewriteMapPtr(1)))
120+
qt.Assert(t, qt.Equals(ins.MapPtr(), 1))
121121

122122
// mapOffset should be unchanged after rewriting the pointer.
123-
qt.Assert(t, ins.mapOffset(), qt.Equals, uint32(321))
123+
qt.Assert(t, qt.Equals(ins.mapOffset(), 321))
124124

125-
qt.Assert(t, ins.RewriteMapOffset(123), qt.IsNil)
126-
qt.Assert(t, ins.mapOffset(), qt.Equals, uint32(123))
125+
qt.Assert(t, qt.IsNil(ins.RewriteMapOffset(123)))
126+
qt.Assert(t, qt.Equals(ins.mapOffset(), 123))
127127

128128
// MapPtr should be unchanged.
129-
qt.Assert(t, ins.MapPtr(), qt.Equals, 1)
129+
qt.Assert(t, qt.Equals(ins.MapPtr(), 1))
130130

131131
ins = Mov.Imm(R1, 32)
132132
if err := ins.RewriteMapPtr(1); err == nil {
@@ -304,34 +304,32 @@ func TestInstructionIterator(t *testing.T) {
304304
}
305305

306306
func TestMetadataCopyOnWrite(t *testing.T) {
307-
c := qt.New(t)
308-
309307
// Setting metadata should copy Instruction and modify the metadata pointer
310308
// of the new object without touching the old Instruction.
311309

312310
// Reference
313311
ins := Ja.Label("my_func")
314312
ins2 := ins.WithReference("my_func2")
315313

316-
c.Assert(ins.Reference(), qt.Equals, "my_func", qt.Commentf("WithReference updated ins"))
317-
c.Assert(ins2.Reference(), qt.Equals, "my_func2", qt.Commentf("WithReference didn't update ins2"))
314+
qt.Assert(t, qt.Equals(ins.Reference(), "my_func"), qt.Commentf("WithReference updated ins"))
315+
qt.Assert(t, qt.Equals(ins2.Reference(), "my_func2"), qt.Commentf("WithReference didn't update ins2"))
318316

319317
// Symbol
320318
ins = Ja.Label("").WithSymbol("my_sym")
321319
ins2 = ins.WithSymbol("my_sym2")
322320

323-
c.Assert(ins.Symbol(), qt.Equals, "my_sym", qt.Commentf("WithSymbol updated ins"))
324-
c.Assert(ins2.Symbol(), qt.Equals, "my_sym2", qt.Commentf("WithSymbol didn't update ins2"))
321+
qt.Assert(t, qt.Equals(ins.Symbol(), "my_sym"), qt.Commentf("WithSymbol updated ins"))
322+
qt.Assert(t, qt.Equals(ins2.Symbol(), "my_sym2"), qt.Commentf("WithSymbol didn't update ins2"))
325323

326324
// Map
327325
ins = LoadMapPtr(R1, 0)
328326
ins2 = ins
329327

330328
testMap := testFDer(1)
331-
c.Assert(ins2.AssociateMap(testMap), qt.IsNil, qt.Commentf("failed to associate map with ins2"))
329+
qt.Assert(t, qt.IsNil(ins2.AssociateMap(testMap)), qt.Commentf("failed to associate map with ins2"))
332330

333-
c.Assert(ins.Map(), qt.IsNil, qt.Commentf("AssociateMap updated ins"))
334-
c.Assert(ins2.Map(), qt.Equals, testMap, qt.Commentf("AssociateMap didn't update ins2"))
331+
qt.Assert(t, qt.IsNil(ins.Map()), qt.Commentf("AssociateMap updated ins"))
332+
qt.Assert(t, qt.Equals[FDer](ins2.Map(), testMap), qt.Commentf("AssociateMap didn't update ins2"))
335333
}
336334

337335
type testFDer int

asm/metadata_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ import (
44
"testing"
55
"unsafe"
66

7-
qt "github.com/frankban/quicktest"
7+
"github.com/go-quicktest/qt"
88
)
99

1010
func TestMetadata(t *testing.T) {
1111
var m Metadata
1212

1313
// Metadata should be the size of a pointer.
14-
qt.Assert(t, unsafe.Sizeof(m), qt.Equals, unsafe.Sizeof(uintptr(0)))
14+
qt.Assert(t, qt.Equals(unsafe.Sizeof(m), unsafe.Sizeof(uintptr(0))))
1515

1616
// A lookup in a nil meta should return nil.
17-
qt.Assert(t, m.Get(bool(false)), qt.IsNil)
17+
qt.Assert(t, qt.IsNil(m.Get(bool(false))))
1818

1919
// We can look up anything we inserted.
2020
m.Set(bool(false), int(0))
2121
m.Set(int(1), int(1))
22-
qt.Assert(t, m.Get(bool(false)), qt.Equals, int(0))
23-
qt.Assert(t, m.Get(int(1)), qt.Equals, int(1))
22+
qt.Assert(t, qt.Equals(m.Get(bool(false)), 0))
23+
qt.Assert(t, qt.Equals(m.Get(1), 1))
2424

2525
// We have copy on write semantics
2626
old := m
2727
m.Set(bool(false), int(1))
28-
qt.Assert(t, m.Get(bool(false)), qt.Equals, int(1))
29-
qt.Assert(t, m.Get(int(1)), qt.Equals, int(1))
30-
qt.Assert(t, old.Get(bool(false)), qt.Equals, int(0))
31-
qt.Assert(t, old.Get(int(1)), qt.Equals, int(1))
28+
qt.Assert(t, qt.Equals(m.Get(bool(false)), 1))
29+
qt.Assert(t, qt.Equals(m.Get(int(1)), 1))
30+
qt.Assert(t, qt.Equals(old.Get(bool(false)), 0))
31+
qt.Assert(t, qt.Equals(old.Get(int(1)), 1))
3232

3333
// Newtypes are handled distinctly.
3434
type b bool
3535
m.Set(b(false), int(42))
36-
qt.Assert(t, m.Get(bool(false)), qt.Equals, int(1))
37-
qt.Assert(t, m.Get(int(1)), qt.Equals, int(1))
38-
qt.Assert(t, m.Get(b(false)), qt.Equals, int(42))
36+
qt.Assert(t, qt.Equals(m.Get(bool(false)), 1))
37+
qt.Assert(t, qt.Equals(m.Get(int(1)), 1))
38+
qt.Assert(t, qt.Equals(m.Get(b(false)), 42))
3939

4040
// Setting nil removes a key.
4141
m.Set(bool(false), nil)
42-
qt.Assert(t, m.Get(bool(false)), qt.IsNil)
43-
qt.Assert(t, m.Get(int(1)), qt.Equals, int(1))
44-
qt.Assert(t, m.Get(b(false)), qt.Equals, int(42))
42+
qt.Assert(t, qt.IsNil(m.Get(bool(false))))
43+
qt.Assert(t, qt.Equals(m.Get(int(1)), 1))
44+
qt.Assert(t, qt.Equals(m.Get(b(false)), 42))
4545
}
4646

4747
func BenchmarkMetadata(b *testing.B) {

asm/opcode_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7-
qt "github.com/frankban/quicktest"
7+
"github.com/go-quicktest/qt"
88
)
99

1010
func TestGetSetJumpOp(t *testing.T) {
@@ -13,11 +13,11 @@ func TestGetSetJumpOp(t *testing.T) {
1313
opcode := OpCode(class).SetJumpOp(op)
1414

1515
if valid {
16-
qt.Assert(t, opcode, qt.Not(qt.Equals), InvalidOpCode)
17-
qt.Assert(t, opcode.JumpOp(), qt.Equals, op)
16+
qt.Assert(t, qt.Not(qt.Equals(opcode, InvalidOpCode)))
17+
qt.Assert(t, qt.Equals(opcode.JumpOp(), op))
1818
} else {
19-
qt.Assert(t, opcode, qt.Equals, InvalidOpCode)
20-
qt.Assert(t, opcode.JumpOp(), qt.Equals, InvalidJumpOp)
19+
qt.Assert(t, qt.Equals(opcode, InvalidOpCode))
20+
qt.Assert(t, qt.Equals(opcode.JumpOp(), InvalidJumpOp))
2121
}
2222
})
2323
}

btf/btf_test.go

+17-16
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
"os"
1010
"testing"
1111

12+
"github.com/go-quicktest/qt"
13+
1214
"github.com/cilium/ebpf/internal"
1315
"github.com/cilium/ebpf/internal/testutils"
14-
qt "github.com/frankban/quicktest"
1516
)
1617

1718
func vmlinuxSpec(tb testing.TB) *Spec {
@@ -339,10 +340,10 @@ func TestSpecCopy(t *testing.T) {
339340
cpy := spec.Copy()
340341

341342
have := typesFromSpec(t, spec)
342-
qt.Assert(t, len(spec.types) > 0, qt.IsTrue)
343+
qt.Assert(t, qt.IsTrue(len(spec.types) > 0))
343344

344345
want := typesFromSpec(t, cpy)
345-
qt.Assert(t, want, qt.HasLen, len(have))
346+
qt.Assert(t, qt.HasLen(want, len(have)))
346347

347348
for i := range want {
348349
if _, ok := have[i].(*Void); ok {
@@ -362,10 +363,10 @@ func TestSpecTypeByID(t *testing.T) {
362363
spec := specFromTypes(t, nil)
363364

364365
_, err := spec.TypeByID(0)
365-
qt.Assert(t, err, qt.IsNil)
366+
qt.Assert(t, qt.IsNil(err))
366367

367368
_, err = spec.TypeByID(1)
368-
qt.Assert(t, err, qt.ErrorIs, ErrNotFound)
369+
qt.Assert(t, qt.ErrorIs(err, ErrNotFound))
369370
}
370371

371372
func ExampleSpec_TypeByName() {
@@ -409,7 +410,7 @@ func TestTypesIterator(t *testing.T) {
409410
t.Fatal("Iterator ended early at item", i)
410411
}
411412

412-
qt.Assert(t, iter.Type, qt.DeepEquals, typ)
413+
qt.Assert(t, qt.DeepEquals(iter.Type, typ))
413414
}
414415

415416
if iter.Next() {
@@ -441,8 +442,8 @@ func TestLoadSplitSpecFromReader(t *testing.T) {
441442
}
442443

443444
typeByID, err := splitSpec.TypeByID(typeID)
444-
qt.Assert(t, err, qt.IsNil)
445-
qt.Assert(t, typeByID, qt.Equals, typ)
445+
qt.Assert(t, qt.IsNil(err))
446+
qt.Assert(t, qt.Equals(typeByID, typ))
446447

447448
fnType := typ.(*Func)
448449
fnProto := fnType.Type.(*FuncProto)
@@ -492,15 +493,15 @@ func TestFixupDatasecLayout(t *testing.T) {
492493
},
493494
}
494495

495-
qt.Assert(t, fixupDatasecLayout(ds), qt.IsNil)
496+
qt.Assert(t, qt.IsNil(fixupDatasecLayout(ds)))
496497

497-
qt.Assert(t, ds.Size, qt.Equals, uint32(40))
498-
qt.Assert(t, ds.Vars[0].Offset, qt.Equals, uint32(0))
499-
qt.Assert(t, ds.Vars[1].Offset, qt.Equals, uint32(4))
500-
qt.Assert(t, ds.Vars[2].Offset, qt.Equals, uint32(5))
501-
qt.Assert(t, ds.Vars[3].Offset, qt.Equals, uint32(6))
502-
qt.Assert(t, ds.Vars[4].Offset, qt.Equals, uint32(16))
503-
qt.Assert(t, ds.Vars[5].Offset, qt.Equals, uint32(32))
498+
qt.Assert(t, qt.Equals(ds.Size, 40))
499+
qt.Assert(t, qt.Equals(ds.Vars[0].Offset, 0))
500+
qt.Assert(t, qt.Equals(ds.Vars[1].Offset, 4))
501+
qt.Assert(t, qt.Equals(ds.Vars[2].Offset, 5))
502+
qt.Assert(t, qt.Equals(ds.Vars[3].Offset, 6))
503+
qt.Assert(t, qt.Equals(ds.Vars[4].Offset, 16))
504+
qt.Assert(t, qt.Equals(ds.Vars[5].Offset, 32))
504505
}
505506

506507
func BenchmarkSpecCopy(b *testing.B) {

btf/core_test.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"strings"
88
"testing"
99

10+
"github.com/google/go-cmp/cmp"
11+
1012
"github.com/cilium/ebpf/internal"
1113
"github.com/cilium/ebpf/internal/testutils"
12-
"github.com/google/go-cmp/cmp"
1314

14-
qt "github.com/frankban/quicktest"
15+
"github.com/go-quicktest/qt"
1516
"golang.org/x/exp/slices"
1617
)
1718

@@ -256,9 +257,9 @@ func TestCOREFindEnumValue(t *testing.T) {
256257
for _, test := range valid {
257258
t.Run(test.name, func(t *testing.T) {
258259
local, target, err := coreFindEnumValue(test.local, test.acc, test.target)
259-
qt.Assert(t, err, qt.IsNil)
260-
qt.Check(t, local.Value, qt.Equals, test.localValue)
261-
qt.Check(t, target.Value, qt.Equals, test.targetValue)
260+
qt.Assert(t, qt.IsNil(err))
261+
qt.Check(t, qt.Equals(local.Value, test.localValue))
262+
qt.Check(t, qt.Equals(target.Value, test.targetValue))
262263
})
263264
}
264265
}
@@ -523,7 +524,7 @@ func TestCOREFindField(t *testing.T) {
523524
for _, test := range valid {
524525
t.Run(test.name, func(t *testing.T) {
525526
localField, targetField, err := coreFindField(test.local, test.acc, test.target)
526-
qt.Assert(t, err, qt.IsNil)
527+
qt.Assert(t, qt.IsNil(err))
527528
checkCOREField(t, "local", localField, test.localField)
528529
checkCOREField(t, "target", targetField, test.targetField)
529530
})
@@ -632,8 +633,8 @@ func TestCORECopyWithoutQualifiers(t *testing.T) {
632633
root.Type = test.fn(root)
633634

634635
cycle, ok := Copy(root, UnderlyingType).(*cycle)
635-
qt.Assert(t, ok, qt.IsTrue)
636-
qt.Assert(t, cycle.root, qt.Equals, root)
636+
qt.Assert(t, qt.IsTrue(ok))
637+
qt.Assert(t, qt.Equals[Type](cycle.root, root))
637638
})
638639
}
639640

@@ -644,7 +645,7 @@ func TestCORECopyWithoutQualifiers(t *testing.T) {
644645
want := &Pointer{Target: &Int{Name: "z"}}
645646

646647
got := Copy(v, UnderlyingType)
647-
qt.Assert(t, got, qt.DeepEquals, want)
648+
qt.Assert(t, qt.DeepEquals[Type](got, want))
648649
})
649650
}
650651
}
@@ -660,7 +661,7 @@ func TestCORECopyWithoutQualifiers(t *testing.T) {
660661
}
661662

662663
got := Copy(v, UnderlyingType)
663-
qt.Assert(t, got, qt.DeepEquals, root)
664+
qt.Assert(t, qt.DeepEquals[Type](got, root))
664665
})
665666
}
666667

@@ -671,8 +672,8 @@ func TestCOREReloFieldSigned(t *testing.T) {
671672
typ, coreAccessor{0}, reloFieldSigned, 0,
672673
}
673674
fixup, err := coreCalculateFixup(relo, &Void{}, 0, internal.NativeEndian)
674-
qt.Assert(t, fixup.poison, qt.IsTrue)
675-
qt.Assert(t, err, qt.IsNil)
675+
qt.Assert(t, qt.IsTrue(fixup.poison))
676+
qt.Assert(t, qt.IsNil(err))
676677
})
677678
}
678679

@@ -681,7 +682,7 @@ func TestCOREReloFieldSigned(t *testing.T) {
681682
&Array{}, coreAccessor{0}, reloFieldSigned, 0,
682683
}
683684
_, err := coreCalculateFixup(relo, &Array{}, 0, internal.NativeEndian)
684-
qt.Assert(t, err, qt.ErrorIs, errNoSignedness)
685+
qt.Assert(t, qt.ErrorIs(err, errNoSignedness))
685686
})
686687
}
687688

@@ -698,7 +699,7 @@ func TestCOREReloFieldShiftU64(t *testing.T) {
698699
} {
699700
t.Run(relo.kind.String(), func(t *testing.T) {
700701
_, err := coreCalculateFixup(relo, typ, 1, internal.NativeEndian)
701-
qt.Assert(t, err, qt.ErrorIs, errUnsizedType)
702+
qt.Assert(t, qt.ErrorIs(err, errUnsizedType))
702703
})
703704
}
704705
}
@@ -708,22 +709,22 @@ func BenchmarkCORESkBuff(b *testing.B) {
708709

709710
var skb *Struct
710711
err := spec.TypeByName("sk_buff", &skb)
711-
qt.Assert(b, err, qt.IsNil)
712+
qt.Assert(b, qt.IsNil(err))
712713

713714
skbID, err := spec.TypeID(skb)
714-
qt.Assert(b, err, qt.IsNil)
715+
qt.Assert(b, qt.IsNil(err))
715716

716717
lenIndex := slices.IndexFunc(skb.Members, func(m Member) bool {
717718
return m.Name == "len"
718719
})
719-
qt.Assert(b, lenIndex, qt.Not(qt.Equals), -1)
720+
qt.Assert(b, qt.Not(qt.Equals(lenIndex, -1)))
720721

721722
var pktHashTypes *Enum
722723
err = spec.TypeByName("pkt_hash_types", &pktHashTypes)
723-
qt.Assert(b, err, qt.IsNil)
724+
qt.Assert(b, qt.IsNil(err))
724725

725726
pktHashTypesID, err := spec.TypeID(pktHashTypes)
726-
qt.Assert(b, err, qt.IsNil)
727+
qt.Assert(b, qt.IsNil(err))
727728

728729
for _, relo := range []*CORERelocation{
729730
{skb, coreAccessor{0, lenIndex}, reloFieldByteOffset, skbID},

0 commit comments

Comments
 (0)