Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package memc

import (
"bufio"
"errors"
"io"
"math"
Expand Down Expand Up @@ -113,6 +114,27 @@ func Test_benign(t *testing.T) {
})
}

func Test_getPayload_capacity(t *testing.T) {
t.Parallel()

t.Run("get", func(t *testing.T) {
r := bufio.NewReader(strings.NewReader("VALUE foo 0 5\r\nhello\r\nEND\r\n"))
b, err := getPayload(r)
must.NoError(t, err)
must.Eq(t, []byte("hello"), b)
must.Eq(t, len(b), cap(b))
})

t.Run("gets", func(t *testing.T) {
r := bufio.NewReader(strings.NewReader("VALUE foo 0 5 99\r\nhello\r\nEND\r\n"))
b, cas, err := getPayloadWithCAS(r)
must.NoError(t, err)
must.Eq(t, uint64(99), cas)
must.Eq(t, []byte("hello"), b)
must.Eq(t, len(b), cap(b))
})
}

func Test_SetDefaultTTL(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions verbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func getPayload(r *bufio.Reader) ([]byte, error) {
if _, err = io.ReadFull(r, payload); err != nil {
return nil, err
}
payload = payload[0:size] // chop \r\n
payload = payload[:size:size] // chop \r\n and cap capacity

// read the trailing line ("END\r\n")
b, err = r.ReadSlice('\n')
Expand Down Expand Up @@ -697,7 +697,7 @@ func getPayloadWithCAS(r *bufio.Reader) ([]byte, uint64, error) {
if _, err = io.ReadFull(r, payload); err != nil {
return nil, 0, err
}
payload = payload[0:size] // chop \r\n
payload = payload[:size:size] // chop \r\n and cap capacity

// read the trailing line ("END\r\n")
b, err = r.ReadSlice('\n')
Expand Down
Loading