aboutsummaryrefslogtreecommitdiff
path: root/hotline/server_blackbox_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-24 16:23:56 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-24 16:23:56 -0700
commita2ef262a164fc735b9b8471ac0c8001eea2b9bf6 (patch)
tree9a24fc5949df1183895a125e09cb262cdf79b073 /hotline/server_blackbox_test.go
parenta55350daaf83498b7a237c027ad0dd2377f06fee (diff)
Refactoring, cleanup, test backfilling
Diffstat (limited to 'hotline/server_blackbox_test.go')
-rw-r--r--hotline/server_blackbox_test.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/hotline/server_blackbox_test.go b/hotline/server_blackbox_test.go
index 28aecf0..06e7771 100644
--- a/hotline/server_blackbox_test.go
+++ b/hotline/server_blackbox_test.go
@@ -1,10 +1,13 @@
package hotline
import (
+ "cmp"
+ "encoding/binary"
"encoding/hex"
"github.com/stretchr/testify/assert"
"log/slog"
"os"
+ "slices"
"testing"
)
@@ -30,6 +33,13 @@ func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool
return assert.Equal(t, wantHexDump, hex.Dump(clean))
}
+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 ID
func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
var newT1 []Transaction
@@ -45,7 +55,7 @@ func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
continue
}
- trans.Fields = append(trans.Fields, field)
+ fs = append(fs, field)
}
trans.Fields = fs
newT1 = append(newT1, trans)
@@ -61,11 +71,14 @@ func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
continue
}
- trans.Fields = append(trans.Fields, field)
+ 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)
}