7 "github.com/stretchr/testify/assert"
14 func NewTestLogger() *slog.Logger {
15 return slog.New(slog.NewTextHandler(os.Stdout, nil))
18 // assertTransferBytesEqual takes a string with a hexdump in the same format that `hexdump -C` produces and compares with
19 // a hexdump for the bytes in got, after stripping the create/modify timestamps.
20 // I don't love this, but as git does not preserve file create/modify timestamps, we either need to fully mock the
21 // filesystem interactions or work around in this way.
22 // TODO: figure out a better solution
23 func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool {
24 if wantHexDump == "" {
29 clean = append(clean, got[:92]...) // keep the first 92 bytes
30 clean = append(clean, make([]byte, 16)...) // replace the next 16 bytes for create/modify timestamps
31 clean = append(clean, got[108:]...) // keep the rest
33 return assert.Equal(t, wantHexDump, hex.Dump(clean))
36 var tranSortFunc = func(a, b Transaction) int {
38 binary.BigEndian.Uint16(a.clientID[:]),
39 binary.BigEndian.Uint16(b.clientID[:]),
43 // tranAssertEqual compares equality of transactions slices after stripping out the random transaction ID
44 func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
45 var newT1 []Transaction
46 var newT2 []Transaction
48 for _, trans := range tran1 {
49 trans.ID = [4]byte{0, 0, 0, 0}
51 for _, field := range trans.Fields {
52 if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
55 if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
58 fs = append(fs, field)
61 newT1 = append(newT1, trans)
64 for _, trans := range tran2 {
65 trans.ID = [4]byte{0, 0, 0, 0}
67 for _, field := range trans.Fields {
68 if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
71 if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
74 fs = append(fs, field)
77 newT2 = append(newT2, trans)
80 slices.SortFunc(newT1, tranSortFunc)
81 slices.SortFunc(newT2, tranSortFunc)
83 return assert.Equal(t, newT1, newT2)