Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions internal/proto/peek_push_notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,25 +295,26 @@ func createValidPushNotification(notificationName, data string) *bytes.Buffer {
buf := &bytes.Buffer{}

simpleOrString := rand.Intn(2) == 0
defMsg := fmt.Sprintf("$%d\r\n%s\r\n", len(notificationName), notificationName)

if data == "" {

// Single element notification
buf.WriteString(">1\r\n")
if simpleOrString {
buf.WriteString(fmt.Sprintf("+%s\r\n", notificationName))
fmt.Fprint(buf, defMsg)
} else {
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(notificationName), notificationName))
fmt.Fprint(buf, defMsg)
}
} else {
// Two element notification
buf.WriteString(">2\r\n")
if simpleOrString {
buf.WriteString(fmt.Sprintf("+%s\r\n", notificationName))
buf.WriteString(fmt.Sprintf("+%s\r\n", data))
fmt.Fprintf(buf, "+%s\r\n", notificationName)
fmt.Fprintf(buf, "+%s\r\n", data)
} else {
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(notificationName), notificationName))
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(notificationName), notificationName))
fmt.Fprint(buf, defMsg)
fmt.Fprint(buf, defMsg)
}
}

Expand All @@ -333,14 +334,14 @@ func createPushNotificationWithArgs(notificationName string, args ...string) *by
buf := &bytes.Buffer{}

totalElements := 1 + len(args)
buf.WriteString(fmt.Sprintf(">%d\r\n", totalElements))
fmt.Fprintf(buf, ">%d\r\n", totalElements)

// Write notification name
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(notificationName), notificationName))
fmt.Fprintf(buf, "$%d\r\n%s\r\n", len(notificationName), notificationName)

// Write arguments
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
Expand All @@ -350,7 +351,7 @@ func createPushNotificationWithArgs(notificationName string, args ...string) *by
func createSingleElementPushNotification(notificationName string) *bytes.Buffer {
buf := &bytes.Buffer{}
buf.WriteString(">1\r\n")
buf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(notificationName), notificationName))
fmt.Fprintf(buf, "$%d\r\n%s\r\n", len(notificationName), notificationName)
return buf
}

Expand Down
12 changes: 6 additions & 6 deletions push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}

Expand Down
Loading