@@ -11,12 +11,17 @@ import (
1111 "github.com/tidwall/redcon"
1212)
1313
14+ // Tagged types to distinguish RESP wire types in mock writes.
15+ type respInt struct { V int } // WriteInt
16+ type respInt64 struct { V int64 } // WriteInt64
17+ type respArray struct { N int } // WriteArray
18+
1419// mockDetachedConn implements redcon.DetachedConn for unit testing.
1520type mockDetachedConn struct {
1621 mu sync.Mutex
1722 commands []redcon.Command // queued commands to return from ReadCommand
1823 cmdIdx int
19- writes []any // recorded writes: string for WriteString/WriteError/WriteBulkString, int for WriteInt/WriteArray , nil for WriteNull
24+ writes []any // recorded writes: string for WriteString/WriteError/WriteBulkString, respInt/respInt64/respArray for typed ints , nil for WriteNull
2025 closed bool
2126 readErr error // error to return from ReadCommand when commands exhausted
2227}
@@ -74,20 +79,20 @@ func (m *mockDetachedConn) WriteBulkString(bulk string) {
7479func (m * mockDetachedConn ) WriteInt (num int ) {
7580 m .mu .Lock ()
7681 defer m .mu .Unlock ()
77- m .writes = append (m .writes , num )
82+ m .writes = append (m .writes , respInt { num } )
7883}
7984func (m * mockDetachedConn ) WriteInt64 (num int64 ) {
8085 m .mu .Lock ()
8186 defer m .mu .Unlock ()
82- m .writes = append (m .writes , int ( num ) )
87+ m .writes = append (m .writes , respInt64 { num } )
8388}
8489func (m * mockDetachedConn ) WriteUint64 (_ uint64 ) {
8590 // Not used in pubsub tests.
8691}
8792func (m * mockDetachedConn ) WriteArray (count int ) {
8893 m .mu .Lock ()
8994 defer m .mu .Unlock ()
90- m .writes = append (m .writes , count )
95+ m .writes = append (m .writes , respArray { count } )
9196}
9297func (m * mockDetachedConn ) WriteNull () {
9398 m .mu .Lock ()
@@ -201,7 +206,7 @@ func TestPubSub_WriteUnsubAll_PerChannelReplies(t *testing.T) {
201206 // Count array headers (each reply starts with WriteArray(3))
202207 arrCount := 0
203208 for _ , w := range writes {
204- if n , ok := w .(int ); ok && n == 3 {
209+ if a , ok := w .(respArray ); ok && a . N == 3 {
205210 arrCount ++
206211 }
207212 }
@@ -250,7 +255,7 @@ func TestPubSub_WriteUnsubAll_Patterns(t *testing.T) {
250255 // Should have 1 reply (one pattern)
251256 arrCount := 0
252257 for _ , w := range writes {
253- if n , ok := w .(int ); ok && n == 3 {
258+ if a , ok := w .(respArray ); ok && a . N == 3 {
254259 arrCount ++
255260 }
256261 }
@@ -341,7 +346,7 @@ func TestPubSub_HandlePubSubPing(t *testing.T) {
341346
342347 writes := dconn .getWrites ()
343348 // ["pong", ""]
344- assert .Contains (t , writes , 2 ) // WriteArray(2)
349+ assert .Contains (t , writes , respArray { 2 } ) // WriteArray(2)
345350 assert .Contains (t , writes , "BULKSTR:pong" )
346351 assert .Contains (t , writes , "BULKSTR:" ) // empty string
347352}
@@ -372,7 +377,7 @@ func TestPubSub_HandleUnsubNoSession(t *testing.T) {
372377 }
373378 }
374379 assert .True (t , hasNull )
375- assert .Contains (t , writes , 0 ) // WriteInt64(0)
380+ assert .Contains (t , writes , respInt64 { 0 } ) // WriteInt64(0)
376381}
377382
378383func TestPubSub_SubscribeInTxnRejected (t * testing.T ) {
0 commit comments