]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server_blackbox_test.go
Limit chat message size to 8192 bytes
[rbdr/mobius] / hotline / server_blackbox_test.go
index 27ac4a7a313ae8108c38bba238efcd206d9a6e81..06e7771eef1342d84402235206d2fb489f576aed 100644 (file)
@@ -1,11 +1,13 @@
 package hotline
 
 import (
-       "bytes"
+       "cmp"
+       "encoding/binary"
        "encoding/hex"
        "github.com/stretchr/testify/assert"
        "log/slog"
        "os"
+       "slices"
        "testing"
 )
 
@@ -31,16 +33,26 @@ func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool
        return assert.Equal(t, wantHexDump, hex.Dump(clean))
 }
 
-// tranAssertEqual compares equality of transactions slices after stripping out the random ID
+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
        var newT2 []Transaction
 
        for _, trans := range tran1 {
-               trans.ID = []byte{0, 0, 0, 0}
+               trans.ID = [4]byte{0, 0, 0, 0}
                var fs []Field
                for _, field := range trans.Fields {
-                       if bytes.Equal(field.ID, []byte{0x00, 0x6b}) {
+                       if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
+                               continue
+                       }
+                       if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
                                continue
                        }
                        fs = append(fs, field)
@@ -50,10 +62,13 @@ func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
        }
 
        for _, trans := range tran2 {
-               trans.ID = []byte{0, 0, 0, 0}
+               trans.ID = [4]byte{0, 0, 0, 0}
                var fs []Field
                for _, field := range trans.Fields {
-                       if bytes.Equal(field.ID, []byte{0x00, 0x6b}) {
+                       if field.ID == [2]byte{0x00, 0x6b} { // FieldRefNum
+                               continue
+                       }
+                       if field.ID == [2]byte{0x00, 0x72} { // FieldChatID
                                continue
                        }
                        fs = append(fs, field)
@@ -62,5 +77,8 @@ func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
                newT2 = append(newT2, trans)
        }
 
+       slices.SortFunc(newT1, tranSortFunc)
+       slices.SortFunc(newT2, tranSortFunc)
+
        return assert.Equal(t, newT1, newT2)
 }