package hotline
import (
+ "cmp"
+ "encoding/binary"
"encoding/hex"
"github.com/stretchr/testify/assert"
"log/slog"
"os"
+ "slices"
"testing"
)
return true
}
- var clean []byte
- clean = append(clean, got[:92]...) // keep the first 92 bytes
- clean = append(clean, make([]byte, 16)...) // replace the next 16 bytes for create/modify timestamps
- clean = append(clean, got[108:]...) // keep the rest
-
+ clean := slices.Concat(
+ got[:92],
+ make([]byte, 16),
+ got[108:],
+ )
return assert.Equal(t, wantHexDump, hex.Dump(clean))
}
-// tranAssertEqual compares equality of transactions slices after stripping out the random transaction ID
-func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
+var tranSortFunc = func(a, b Transaction) int {
+ return cmp.Compare(
+ binary.BigEndian.Uint16(a.ClientID[:]),
+ binary.BigEndian.Uint16(b.ClientID[:]),
+ )
+}
+
+// TranAssertEqual compares equality of transactions slices after stripping out the random transaction Type
+func TranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
var newT1 []Transaction
var newT2 []Transaction
trans.ID = [4]byte{0, 0, 0, 0}
var fs []Field
for _, field := range trans.Fields {
- if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
+ if field.Type == FieldRefNum { // FieldRefNum
continue
}
- if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
+ if field.Type == FieldChatID { // FieldChatID
continue
}
+
fs = append(fs, field)
}
trans.Fields = fs
trans.ID = [4]byte{0, 0, 0, 0}
var fs []Field
for _, field := range trans.Fields {
- if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
+ if field.Type == FieldRefNum { // FieldRefNum
continue
}
- if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
+ if field.Type == FieldChatID { // FieldChatID
continue
}
+
fs = append(fs, field)
}
trans.Fields = fs
newT2 = append(newT2, trans)
}
+ slices.SortFunc(newT1, tranSortFunc)
+ slices.SortFunc(newT2, tranSortFunc)
+
return assert.Equal(t, newT1, newT2)
}