@@ -95,7 +95,7 @@ func TestPeekPushNotificationName(t *testing.T) {
9595 t .Run ("NotPushNotification" , func (t * testing.T ) {
9696 // Test with regular array instead of push notification
9797 buf := & bytes.Buffer {}
98- buf . WriteString ( "*2\r \n $6\r \n MOVING\r \n $4\r \n data\r \n " )
98+ fmt . Fprint ( buf , "*2\r \n $6\r \n MOVING\r \n $4\r \n data\r \n " )
9999 reader := NewReader (buf )
100100
101101 _ , err := reader .PeekPushNotificationName ()
@@ -112,7 +112,7 @@ func TestPeekPushNotificationName(t *testing.T) {
112112 t .Run ("InsufficientData" , func (t * testing.T ) {
113113 // Test with buffer smaller than peek size - this might panic due to bounds checking
114114 buf := & bytes.Buffer {}
115- buf . WriteString ( ">" )
115+ fmt . Fprint ( buf , ">" )
116116 reader := NewReader (buf )
117117
118118 func () {
@@ -146,7 +146,7 @@ func TestPeekPushNotificationName(t *testing.T) {
146146 t .Run (fmt .Sprintf ("Type_%c" , respType ), func (t * testing.T ) {
147147 buf := & bytes.Buffer {}
148148 buf .WriteByte (respType )
149- buf . WriteString ( "test data that fills the buffer completely" )
149+ fmt . Fprint ( buf , "test data that fills the buffer completely" )
150150 reader := NewReader (buf )
151151
152152 _ , err := reader .PeekPushNotificationName ()
@@ -167,7 +167,7 @@ func TestPeekPushNotificationName(t *testing.T) {
167167 t .Run ("ZeroLengthArray" , func (t * testing.T ) {
168168 // Create push notification with zero elements: >0\r\n
169169 buf := & bytes.Buffer {}
170- buf . WriteString ( ">0\r \n padding_data_to_fill_buffer_completely" )
170+ fmt . Fprint ( buf , ">0\r \n padding_data_to_fill_buffer_completely" )
171171 reader := NewReader (buf )
172172
173173 _ , err := reader .PeekPushNotificationName ()
@@ -209,7 +209,7 @@ func TestPeekPushNotificationName(t *testing.T) {
209209 for _ , tc := range corruptedCases {
210210 t .Run (tc .name , func (t * testing.T ) {
211211 buf := & bytes.Buffer {}
212- buf . WriteString ( tc .data )
212+ fmt . Fprint ( buf , tc .data )
213213 reader := NewReader (buf )
214214
215215 // Some corrupted data might not error but return unexpected results
@@ -230,7 +230,7 @@ func TestPeekPushNotificationName(t *testing.T) {
230230 // Create buffer that is exactly 36 bytes (the peek window size)
231231 buf := & bytes.Buffer {}
232232 // ">1\r\n$4\r\nTEST\r\n" = 14 bytes, need 22 more
233- buf . WriteString ( ">1\r \n $4\r \n TEST\r \n 1234567890123456789012" )
233+ fmt . Fprint ( buf , ">1\r \n $4\r \n TEST\r \n 1234567890123456789012" )
234234 if buf .Len () != 36 {
235235 t .Errorf ("Expected buffer length 36, got %d" , buf .Len ())
236236 }
@@ -295,25 +295,26 @@ func createValidPushNotification(notificationName, data string) *bytes.Buffer {
295295 buf := & bytes.Buffer {}
296296
297297 simpleOrString := rand .Intn (2 ) == 0
298+ defMsg := fmt .Sprintf ("$%d\r \n %s\r \n " , len (notificationName ), notificationName )
298299
299300 if data == "" {
300301
301302 // Single element notification
302- buf . WriteString ( ">1\r \n " )
303+ fmt . Fprint ( buf , ">1\r \n " )
303304 if simpleOrString {
304- buf . WriteString ( fmt .Sprintf ( "+%s\r \n " , notificationName ) )
305+ fmt .Fprintf ( buf , "+%s\r \n " , notificationName )
305306 } else {
306- buf . WriteString ( fmt .Sprintf ( "$%d \r \n %s \r \n " , len ( notificationName ), notificationName ) )
307+ fmt .Fprint ( buf , defMsg )
307308 }
308309 } else {
309310 // Two element notification
310- buf . WriteString ( ">2\r \n " )
311+ fmt . Fprint ( buf , ">2\r \n " )
311312 if simpleOrString {
312- buf . WriteString ( fmt .Sprintf ( "+%s\r \n " , notificationName ) )
313- buf . WriteString ( fmt .Sprintf ( "+%s\r \n " , data ) )
313+ fmt .Fprintf ( buf , "+%s\r \n " , notificationName )
314+ fmt .Fprintf ( buf , "+%s\r \n " , data )
314315 } else {
315- buf . WriteString ( fmt .Sprintf ( "$%d \r \n %s \r \n " , len ( notificationName ), notificationName ) )
316- buf . WriteString ( fmt .Sprintf ( "$%d \r \n %s \r \n " , len ( notificationName ), notificationName ) )
316+ fmt .Fprint ( buf , defMsg )
317+ fmt .Fprint ( buf , defMsg )
317318 }
318319 }
319320
@@ -333,14 +334,14 @@ func createPushNotificationWithArgs(notificationName string, args ...string) *by
333334 buf := & bytes.Buffer {}
334335
335336 totalElements := 1 + len (args )
336- buf . WriteString ( fmt .Sprintf ( ">%d\r \n " , totalElements ) )
337+ fmt .Fprintf ( buf , ">%d\r \n " , totalElements )
337338
338339 // Write notification name
339- buf . WriteString ( fmt .Sprintf ( "$%d\r \n %s\r \n " , len (notificationName ), notificationName ) )
340+ fmt .Fprintf ( buf , "$%d\r \n %s\r \n " , len (notificationName ), notificationName )
340341
341342 // Write arguments
342343 for _ , arg := range args {
343- buf . WriteString ( fmt .Sprintf ( "$%d\r \n %s\r \n " , len (arg ), arg ) )
344+ fmt .Fprintf ( buf , "$%d\r \n %s\r \n " , len (arg ), arg )
344345 }
345346
346347 return buf
@@ -349,8 +350,8 @@ func createPushNotificationWithArgs(notificationName string, args ...string) *by
349350// createSingleElementPushNotification creates a push notification with single element
350351func createSingleElementPushNotification (notificationName string ) * bytes.Buffer {
351352 buf := & bytes.Buffer {}
352- buf . WriteString ( ">1\r \n " )
353- buf . WriteString ( fmt .Sprintf ( "$%d\r \n %s\r \n " , len (notificationName ), notificationName ) )
353+ fmt . Fprint ( buf , ">1\r \n " )
354+ fmt .Fprintf ( buf , "$%d\r \n %s\r \n " , len (notificationName ), notificationName )
354355 return buf
355356}
356357
0 commit comments