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
16 changes: 5 additions & 11 deletions crud/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmihailenco/msgpack/v5"

"github.com/tarantool/go-tarantool/v3/crud"
Expand Down Expand Up @@ -104,20 +106,12 @@ func TestOperation_EncodeMsgpack(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
var refBuf bytes.Buffer
encRef := msgpack.NewEncoder(&refBuf)
if err := encRef.Encode(test.ref); err != nil {
t.Errorf("error while encoding: %v", err.Error())
}
require.NoError(t, encRef.Encode(test.ref), "error while encoding reference")

var buf bytes.Buffer
enc := msgpack.NewEncoder(&buf)

if err := enc.Encode(test.op); err != nil {
t.Errorf("error while encoding: %v", err.Error())
}
if !bytes.Equal(refBuf.Bytes(), buf.Bytes()) {
t.Errorf("encode response is wrong:\n expected %v\n got: %v",
refBuf, buf.Bytes())
}
require.NoError(t, enc.Encode(test.op), "error while encoding operation")
assert.Equal(t, refBuf.Bytes(), buf.Bytes(), "encode response is wrong")
})
}
}
30 changes: 9 additions & 21 deletions crud/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tarantool/go-iproto"
"github.com/tarantool/go-option"
"github.com/vmihailenco/msgpack/v5"
Expand Down Expand Up @@ -78,18 +80,12 @@ func assertBodyEqual(t testing.TB, reference tarantool.Request, req tarantool.Re
t.Helper()

reqBody, err := extractRequestBody(req)
if err != nil {
t.Fatalf("An unexpected Response.Body() error: %q", err.Error())
}
require.NoError(t, err, "An unexpected Response.Body() error")

refBody, err := extractRequestBody(reference)
if err != nil {
t.Fatalf("An unexpected Response.Body() error: %q", err.Error())
}
require.NoError(t, err, "An unexpected Response.Body() error")

if !bytes.Equal(reqBody, refBody) {
t.Errorf("Encoded request %v != reference %v", reqBody, refBody)
}
assert.Equal(t, refBody, reqBody, "Encoded request body mismatch")
}

func BenchmarkLenRequest(b *testing.B) {
Expand Down Expand Up @@ -164,9 +160,7 @@ func TestRequestsCodes(t *testing.T) {
}

for _, test := range tests {
if rtype := test.req.Type(); rtype != test.rtype {
t.Errorf("An invalid request type 0x%x, expected 0x%x", rtype, test.rtype)
}
assert.Equal(t, test.rtype, test.req.Type(), "An invalid request type")
}
}

Expand Down Expand Up @@ -202,9 +196,7 @@ func TestRequestsAsync(t *testing.T) {
}

for _, test := range tests {
if async := test.req.Async(); async != test.async {
t.Errorf("An invalid async %t, expected %t", async, test.async)
}
assert.Equal(t, test.async, test.req.Async(), "An invalid async value")
}
}

Expand Down Expand Up @@ -240,9 +232,7 @@ func TestRequestsCtx_default(t *testing.T) {
}

for _, test := range tests {
if ctx := test.req.Ctx(); ctx != test.expected {
t.Errorf("An invalid ctx %t, expected %t", ctx, test.expected)
}
assert.Equal(t, test.expected, test.req.Ctx(), "An invalid ctx value")
}
}

Expand Down Expand Up @@ -279,9 +269,7 @@ func TestRequestsCtx_setter(t *testing.T) {
}

for _, test := range tests {
if ctx := test.req.Ctx(); ctx != test.expected {
t.Errorf("An invalid ctx %t, expected %t", ctx, test.expected)
}
assert.Equal(t, test.expected, test.req.Ctx(), "An invalid ctx value")
}
}

Expand Down
Loading
Loading