mirror of
https://github.com/redis/go-redis.git
synced 2025-11-05 14:10:37 +03:00
chore(tests): internal/proto/peek_push_notification_test : Refactor test helpers to… (#3563)
* internal/proto/peek_push_notification_test : Refactor test helpers to use fmt.Fprintf for buffers Replaced buf.WriteString(fmt.Sprintf(...)) with fmt.Fprintf or fmt.Fprint in test helper functions for improved clarity and efficiency. This change affects push notification and RESP3 test utilities. * peek_push_notification_test: revert prev formatting * all: replace buf.WriteString with fmt.FprintF for consistency --------- Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
This commit is contained in:
@@ -837,14 +837,14 @@ func createFakeRESP3PushNotification(notificationType string, args ...string) *b
|
||||
|
||||
// RESP3 Push notification format: ><len>\r\n<elements>\r\n
|
||||
totalElements := 1 + len(args) // notification type + arguments
|
||||
buf.WriteString(fmt.Sprintf(">%d\r\n", totalElements))
|
||||
fmt.Fprintf(buf, ">%d\r\n", totalElements)
|
||||
|
||||
// Write notification type as bulk string
|
||||
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(notificationType), notificationType))
|
||||
fmt.Fprintf(buf, "$%d\r\n%s\r\n", len(notificationType), notificationType)
|
||||
|
||||
// Write arguments as bulk strings
|
||||
for _, arg := range args {
|
||||
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(arg), arg))
|
||||
fmt.Fprintf(buf, "$%d\r\n%s\r\n", len(arg), arg)
|
||||
}
|
||||
|
||||
return buf
|
||||
@@ -868,11 +868,11 @@ func createFakeRESP3Array(elements ...string) *bytes.Buffer {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
// RESP3 Array format: *<len>\r\n<elements>\r\n
|
||||
buf.WriteString(fmt.Sprintf("*%d\r\n", len(elements)))
|
||||
fmt.Fprintf(buf, "*%d\r\n", len(elements))
|
||||
|
||||
// Write elements as bulk strings
|
||||
for _, element := range elements {
|
||||
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(element), element))
|
||||
fmt.Fprintf(buf, "$%d\r\n%s\r\n", len(element), element)
|
||||
}
|
||||
|
||||
return buf
|
||||
@@ -881,7 +881,7 @@ func createFakeRESP3Array(elements ...string) *bytes.Buffer {
|
||||
// createFakeRESP3Error creates a fake RESP3 error
|
||||
func createFakeRESP3Error(message string) *bytes.Buffer {
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteString(fmt.Sprintf("-%s\r\n", message))
|
||||
fmt.Fprintf(buf, "-%s\r\n", message)
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -1117,7 +1117,7 @@ func TestProcessorWithFakeBuffer(t *testing.T) {
|
||||
|
||||
// Create fake RESP3 push notification with no elements
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteString(">0\r\n") // Empty push notification
|
||||
fmt.Fprint(buf, ">0\r\n") // Empty push notification
|
||||
reader := createReaderWithPrimedBuffer(buf)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -1154,9 +1154,9 @@ func TestProcessorWithFakeBuffer(t *testing.T) {
|
||||
|
||||
// Create fake RESP3 push notification with integer as first element
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteString(">2\r\n") // 2 elements
|
||||
buf.WriteString(":123\r\n") // Integer instead of string
|
||||
buf.WriteString("$4\r\ndata\r\n") // String data
|
||||
fmt.Fprint(buf, ">2\r\n") // 2 elements
|
||||
fmt.Fprint(buf, ":123\r\n") // Integer instead of string
|
||||
fmt.Fprint(buf, "$4\r\ndata\r\n") // String data
|
||||
reader := proto.NewReader(buf)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -1273,8 +1273,8 @@ func TestVoidProcessorWithFakeBuffer(t *testing.T) {
|
||||
|
||||
// Create invalid RESP3 data
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteString(">1\r\n") // Push notification with 1 element
|
||||
buf.WriteString("invalid\r\n") // Invalid format (should be $<len>\r\n<data>\r\n)
|
||||
fmt.Fprint(buf, ">1\r\n") // Push notification with 1 element
|
||||
fmt.Fprint(buf, "invalid\r\n") // Invalid format (should be $<len>\r\n<data>\r\n)
|
||||
reader := proto.NewReader(buf)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -1332,9 +1332,9 @@ func TestProcessorErrorHandling(t *testing.T) {
|
||||
|
||||
// Create buffer with corrupted RESP3 data
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteString(">2\r\n") // Says 2 elements
|
||||
buf.WriteString("$6\r\nMOVING\r\n") // First element OK
|
||||
buf.WriteString("corrupted") // Second element corrupted (no proper format)
|
||||
fmt.Fprint(buf, ">2\r\n") // Says 2 elements
|
||||
fmt.Fprint(buf, "$6\r\nMOVING\r\n") // First element OK
|
||||
fmt.Fprint(buf, "corrupted") // Second element corrupted (no proper format)
|
||||
reader := proto.NewReader(buf)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -1360,8 +1360,8 @@ func TestProcessorErrorHandling(t *testing.T) {
|
||||
|
||||
// Create buffer with partial RESP3 data
|
||||
buf := &bytes.Buffer{}
|
||||
buf.WriteString(">2\r\n") // Says 2 elements
|
||||
buf.WriteString("$6\r\nMOVING\r\n") // First element OK
|
||||
fmt.Fprint(buf, ">2\r\n") // Says 2 elements
|
||||
fmt.Fprint(buf, "$6\r\nMOVING\r\n") // First element OK
|
||||
// Missing second element
|
||||
reader := proto.NewReader(buf)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user