6 "github.com/stretchr/testify/assert"
12 func NewTestLogger() *slog.Logger {
13 return slog.New(slog.NewTextHandler(os.Stdout, nil))
16 // assertTransferBytesEqual takes a string with a hexdump in the same format that `hexdump -C` produces and compares with
17 // a hexdump for the bytes in got, after stripping the create/modify timestamps.
18 // I don't love this, but as git does not preserve file create/modify timestamps, we either need to fully mock the
19 // filesystem interactions or work around in this way.
20 // TODO: figure out a better solution
21 func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool {
22 if wantHexDump == "" {
27 clean = append(clean, got[:92]...) // keep the first 92 bytes
28 clean = append(clean, make([]byte, 16)...) // replace the next 16 bytes for create/modify timestamps
29 clean = append(clean, got[108:]...) // keep the rest
31 return assert.Equal(t, wantHexDump, hex.Dump(clean))
34 // tranAssertEqual compares equality of transactions slices after stripping out the random ID
35 func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
36 var newT1 []Transaction
37 var newT2 []Transaction
39 for _, trans := range tran1 {
40 trans.ID = []byte{0, 0, 0, 0}
42 for _, field := range trans.Fields {
43 if bytes.Equal(field.ID, []byte{0x00, 0x6b}) {
46 fs = append(fs, field)
49 newT1 = append(newT1, trans)
52 for _, trans := range tran2 {
53 trans.ID = []byte{0, 0, 0, 0}
55 for _, field := range trans.Fields {
56 if bytes.Equal(field.ID, []byte{0x00, 0x6b}) {
59 fs = append(fs, field)
62 newT2 = append(newT2, trans)
65 return assert.Equal(t, newT1, newT2)