5 "github.com/stretchr/testify/assert"
11 func NewTestLogger() *slog.Logger {
12 return slog.New(slog.NewTextHandler(os.Stdout, nil))
15 // assertTransferBytesEqual takes a string with a hexdump in the same format that `hexdump -C` produces and compares with
16 // a hexdump for the bytes in got, after stripping the create/modify timestamps.
17 // I don't love this, but as git does not preserve file create/modify timestamps, we either need to fully mock the
18 // filesystem interactions or work around in this way.
19 // TODO: figure out a better solution
20 func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool {
21 if wantHexDump == "" {
26 clean = append(clean, got[:92]...) // keep the first 92 bytes
27 clean = append(clean, make([]byte, 16)...) // replace the next 16 bytes for create/modify timestamps
28 clean = append(clean, got[108:]...) // keep the rest
30 return assert.Equal(t, wantHexDump, hex.Dump(clean))
33 // tranAssertEqual compares equality of transactions slices after stripping out the random transaction ID
34 func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
35 var newT1 []Transaction
36 var newT2 []Transaction
38 for _, trans := range tran1 {
39 trans.ID = []byte{0, 0, 0, 0}
41 for _, field := range trans.Fields {
42 if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
45 if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
48 fs = append(fs, field)
51 newT1 = append(newT1, trans)
54 for _, trans := range tran2 {
55 trans.ID = []byte{0, 0, 0, 0}
57 for _, field := range trans.Fields {
58 if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
61 if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
64 fs = append(fs, field)
67 newT2 = append(newT2, trans)
70 return assert.Equal(t, newT1, newT2)