From babd1e37a628a588ea98dc996852eb5058c3419e Mon Sep 17 00:00:00 2001 From: Eugene Blikh Date: Thu, 3 Jul 2025 12:20:08 +0300 Subject: [PATCH] tests: added test for Body() methods of requests using golden files --- golden_test.go | 536 ++++++++++++++++++ request_test.go | 2 +- ...with-txn-isolation-is-sync-timeout.msgpack | Bin 0 -> 15 bytes .../begin-with-txn-isolation-is-sync.msgpack | 1 + .../requests/begin-with-txn-isolation.msgpack | 1 + testdata/requests/begin.msgpack | 1 + testdata/requests/call-no-args.msgpack | 1 + .../call-with-args-empty-array.msgpack | 1 + .../requests/call-with-args-mixed.msgpack | Bin 0 -> 58 bytes testdata/requests/call-with-args-nil.msgpack | 1 + testdata/requests/call-with-args.msgpack | 1 + .../requests/call16-with-args-nil.msgpack | 1 + testdata/requests/call16-with-args.msgpack | Bin 0 -> 58 bytes testdata/requests/call16.msgpack | 1 + .../requests/call17-with-args-nil.msgpack | 1 + testdata/requests/call17-with-args.msgpack | Bin 0 -> 58 bytes testdata/requests/call17.msgpack | 1 + testdata/requests/commit-raw.msgpack | 1 + .../requests/commit-with-sync-false.msgpack | 1 + testdata/requests/commit-with-sync.msgpack | 1 + testdata/requests/delete-raw.msgpack | Bin 0 -> 17 bytes testdata/requests/delete-sname-iname.msgpack | 1 + .../requests/delete-sname-inumber.msgpack | 1 + .../requests/delete-snumber-iname.msgpack | 1 + .../requests/delete-snumber-inumber.msgpack | 1 + testdata/requests/delete.msgpack | Bin 0 -> 17 bytes testdata/requests/eval-with-args.msgpack | Bin 0 -> 63 bytes .../requests/eval-with-empty-array.msgpack | 1 + testdata/requests/eval-with-nil.msgpack | 1 + .../requests/eval-with-single-number.msgpack | 1 + testdata/requests/eval.msgpack | 1 + testdata/requests/insert-sname.msgpack | Bin 0 -> 55 bytes testdata/requests/insert-snumber.msgpack | Bin 0 -> 45 bytes testdata/requests/ping.msgpack | 1 + testdata/requests/replace-sname.msgpack | Bin 0 -> 55 bytes testdata/requests/replace-snumber.msgpack | Bin 0 -> 45 bytes testdata/requests/rollback.msgpack | 1 + testdata/requests/select | Bin 0 -> 27 bytes .../requests/select-key-sname-iname.msgpack | Bin 0 -> 77 bytes .../requests/select-key-sname-inumber.msgpack | Bin 0 -> 67 bytes .../requests/select-key-snumber-iname.msgpack | Bin 0 -> 67 bytes .../select-key-snumber-inumber.msgpack | Bin 0 -> 57 bytes testdata/requests/select-sname-iname.msgpack | Bin 0 -> 37 bytes .../requests/select-sname-inumber.msgpack | Bin 0 -> 27 bytes .../requests/select-snumber-iname.msgpack | Bin 0 -> 27 bytes .../requests/select-snumber-inumber.msgpack | Bin 0 -> 17 bytes testdata/requests/select-with-after.msgpack | Bin 0 -> 105 bytes testdata/requests/select-with-key.msgpack | Bin 0 -> 67 bytes .../requests/select-with-optionals.msgpack | Bin 0 -> 25 bytes testdata/requests/update-sname-iname.msgpack | 2 + .../requests/update-sname-inumber.msgpack | 2 + .../requests/update-snumber-iname.msgpack | 2 + testdata/requests/update.msgpack | Bin 0 -> 19 bytes testdata/requests/upsert-sname.msgpack | Bin 0 -> 132 bytes testdata/requests/upsert-snumber.msgpack | Bin 0 -> 122 bytes testdata/requests/upsert.msgpack | 1 + 56 files changed, 568 insertions(+), 1 deletion(-) create mode 100644 golden_test.go create mode 100644 testdata/requests/begin-with-txn-isolation-is-sync-timeout.msgpack create mode 100644 testdata/requests/begin-with-txn-isolation-is-sync.msgpack create mode 100644 testdata/requests/begin-with-txn-isolation.msgpack create mode 100644 testdata/requests/begin.msgpack create mode 100644 testdata/requests/call-no-args.msgpack create mode 100644 testdata/requests/call-with-args-empty-array.msgpack create mode 100644 testdata/requests/call-with-args-mixed.msgpack create mode 100644 testdata/requests/call-with-args-nil.msgpack create mode 100644 testdata/requests/call-with-args.msgpack create mode 100644 testdata/requests/call16-with-args-nil.msgpack create mode 100644 testdata/requests/call16-with-args.msgpack create mode 100644 testdata/requests/call16.msgpack create mode 100644 testdata/requests/call17-with-args-nil.msgpack create mode 100644 testdata/requests/call17-with-args.msgpack create mode 100644 testdata/requests/call17.msgpack create mode 100644 testdata/requests/commit-raw.msgpack create mode 100644 testdata/requests/commit-with-sync-false.msgpack create mode 100644 testdata/requests/commit-with-sync.msgpack create mode 100644 testdata/requests/delete-raw.msgpack create mode 100644 testdata/requests/delete-sname-iname.msgpack create mode 100644 testdata/requests/delete-sname-inumber.msgpack create mode 100644 testdata/requests/delete-snumber-iname.msgpack create mode 100644 testdata/requests/delete-snumber-inumber.msgpack create mode 100644 testdata/requests/delete.msgpack create mode 100644 testdata/requests/eval-with-args.msgpack create mode 100644 testdata/requests/eval-with-empty-array.msgpack create mode 100644 testdata/requests/eval-with-nil.msgpack create mode 100644 testdata/requests/eval-with-single-number.msgpack create mode 100644 testdata/requests/eval.msgpack create mode 100644 testdata/requests/insert-sname.msgpack create mode 100644 testdata/requests/insert-snumber.msgpack create mode 100644 testdata/requests/ping.msgpack create mode 100644 testdata/requests/replace-sname.msgpack create mode 100644 testdata/requests/replace-snumber.msgpack create mode 100644 testdata/requests/rollback.msgpack create mode 100644 testdata/requests/select create mode 100644 testdata/requests/select-key-sname-iname.msgpack create mode 100644 testdata/requests/select-key-sname-inumber.msgpack create mode 100644 testdata/requests/select-key-snumber-iname.msgpack create mode 100644 testdata/requests/select-key-snumber-inumber.msgpack create mode 100644 testdata/requests/select-sname-iname.msgpack create mode 100644 testdata/requests/select-sname-inumber.msgpack create mode 100644 testdata/requests/select-snumber-iname.msgpack create mode 100644 testdata/requests/select-snumber-inumber.msgpack create mode 100644 testdata/requests/select-with-after.msgpack create mode 100644 testdata/requests/select-with-key.msgpack create mode 100644 testdata/requests/select-with-optionals.msgpack create mode 100644 testdata/requests/update-sname-iname.msgpack create mode 100644 testdata/requests/update-sname-inumber.msgpack create mode 100644 testdata/requests/update-snumber-iname.msgpack create mode 100644 testdata/requests/update.msgpack create mode 100644 testdata/requests/upsert-sname.msgpack create mode 100644 testdata/requests/upsert-snumber.msgpack create mode 100644 testdata/requests/upsert.msgpack diff --git a/golden_test.go b/golden_test.go new file mode 100644 index 000000000..271a98ce3 --- /dev/null +++ b/golden_test.go @@ -0,0 +1,536 @@ +package tarantool_test + +import ( + "bytes" + "encoding/json" + "flag" + "fmt" + "os" + "path" + "reflect" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" + "github.com/vmihailenco/msgpack/v5" + + "github.com/tarantool/go-tarantool/v2" +) + +// golden_test.go contains tests that will check that the msgpack +// encoding of the requests body matches the golden files. +// +// Algorithm to add new test: +// 1. Create a new test record in TestGolden (name + Request). +// 2. Run the test with the flag -generate-golden to generate the golden file. +// (for example: `go test . -run=TestGolden -v -generate-golden`) +// 3. Verify that JSON representation of the msgpack is the same as expected. +// 4. Commit the test record. +// +// Example of JSON representation of the msgpack +// ``` +// golden_test.go:80: writing golden file testdata/requests/select-with-optionals.msgpack +// golden_test.go:38: { +// golden_test.go:38: "IPROTO_FETCH_POSITION[31]": true, +// golden_test.go:38: "IPROTO_INDEX_ID[17]": 0, +// golden_test.go:38: "IPROTO_ITERATOR[20]": 5, +// golden_test.go:38: "IPROTO_KEY[32]": [], +// golden_test.go:38: "IPROTO_LIMIT[18]": 123, +// golden_test.go:38: "IPROTO_OFFSET[19]": 123, +// golden_test.go:38: "IPROTO_SPACE_NAME[94]": "table_name" +// golden_test.go:38: } +// ``` +// +// +// In case of any changes in the msgpack encoding/tests, the test will fail with next error: +// +// ``` +// === RUN TestGolden/testdata/requests/select-with-after.msgpack +// golden_test.go:109: +// Error Trace: ../go-tarantool/golden_test.go:73 +// ../go-tarantool/golden_test.go:109 +// Error: Not equal: +// expected: []byte{0x87, 0x14, 0x5, 0x13, 0x0, ..., 0x33, 0x33, 0x33} +// actual : []byte{0x87, 0x14, 0x5, 0x13, 0x0, ..., 0x33, 0x33, 0x33} +// +// Diff: +// --- Expected +// +++ Actual +// @@ -1,3 +1,3 @@ +// ([]uint8) (len=105) { +// - 00000000 87 14 05 13 ... 6e |......{^.table_n| +// + 00000000 87 14 05 13 ... 6e |......|^.table_n| +// 00000010 61 6d 65 11 ... ff |ame.. ...args...| +// Test: TestGolden/testdata/requests/select-with-after.msgpack +// Messages: golden file content is not equal to actual +// golden_test.go:109: expected: +// golden_test.go:63: { +// golden_test.go:63: "IPROTO_AFTER_TUPLE[47]": [ +// golden_test.go:63: 1, +// golden_test.go:63: "args", +// golden_test.go:63: 3, +// golden_test.go:63: "2024-01-01T03:00:00+03:00", +// golden_test.go:63: "gZMIqvDBS3SYYcSrWiZjCA==", +// golden_test.go:63: 1.2 +// golden_test.go:63: ], +// golden_test.go:63: "IPROTO_INDEX_ID[17]": 0, +// golden_test.go:63: "IPROTO_ITERATOR[20]": 5, +// golden_test.go:63: "IPROTO_KEY[32]": [ +// golden_test.go:63: 1, +// golden_test.go:63: "args", +// golden_test.go:63: 3, +// golden_test.go:63: "2024-01-01T03:00:00+03:00", +// golden_test.go:63: "gZMIqvDBS3SYYcSrWiZjCA==", +// golden_test.go:63: 1.2 +// golden_test.go:63: ], +// golden_test.go:63: "IPROTO_LIMIT[18]": 123, +// golden_test.go:63: "IPROTO_OFFSET[19]": 0, +// golden_test.go:63: "IPROTO_SPACE_NAME[94]": "table_name" +// golden_test.go:63: } +// golden_test.go:109: actual: +// golden_test.go:63: { +// golden_test.go:63: "IPROTO_AFTER_TUPLE[47]": [ +// golden_test.go:63: 1, +// golden_test.go:63: "args", +// golden_test.go:63: 3, +// golden_test.go:63: "2024-01-01T03:00:00+03:00", +// golden_test.go:63: "gZMIqvDBS3SYYcSrWiZjCA==", +// golden_test.go:63: 1.2 +// golden_test.go:63: ], +// golden_test.go:63: "IPROTO_INDEX_ID[17]": 0, +// golden_test.go:63: "IPROTO_ITERATOR[20]": 5, +// golden_test.go:63: "IPROTO_KEY[32]": [ +// golden_test.go:63: 1, +// golden_test.go:63: "args", +// golden_test.go:63: 3, +// golden_test.go:63: "2024-01-01T03:00:00+03:00", +// golden_test.go:63: "gZMIqvDBS3SYYcSrWiZjCA==", +// golden_test.go:63: 1.2 +// golden_test.go:63: ], +// golden_test.go:63: "IPROTO_LIMIT[18]": 124, +// golden_test.go:63: "IPROTO_OFFSET[19]": 0, +// golden_test.go:63: "IPROTO_SPACE_NAME[94]": "table_name" +// golden_test.go:63: } +// --- FAIL: TestGolden/testdata/requests/select-with-after.msgpack (0.00s) +// ``` +// Use it to debug the test. +// +// If you want to update the golden file, run delete old file and rerun the test. + +func logMsgpackAsJsonConvert(t *testing.T, data []byte) { + t.Helper() + + var decodedMsgpack map[int]interface{} + + decoder := msgpack.NewDecoder(bytes.NewReader(data)) + require.NoError(t, decoder.Decode(&decodedMsgpack)) + + decodedConvertedMsgpack := map[string]interface{}{} + for k, v := range decodedMsgpack { + decodedConvertedMsgpack[fmt.Sprintf("%s[%d]", iproto.Key(k).String(), k)] = v + } + + encodedJson, err := json.MarshalIndent(decodedConvertedMsgpack, "", " ") + require.NoError(t, err, "failed to convert msgpack to json") + + for _, line := range bytes.Split(encodedJson, []byte("\n")) { + t.Log(string(line)) + } +} + +func compareGoldenMsgpackAndPrintDiff(t *testing.T, name string, data []byte) { + t.Helper() + + testContent, err := os.ReadFile(name) + require.NoError(t, err, "failed to read golden file", name) + + if assert.Equal(t, testContent, data, "golden file content is not equal to actual") { + return + } + + t.Logf("expected:\n") + logMsgpackAsJsonConvert(t, testContent) + t.Logf("actual:\n") + logMsgpackAsJsonConvert(t, data) +} + +func fileExists(name string) bool { + _, err := os.Stat(name) + return !os.IsNotExist(err) +} + +const ( + pathPrefix = "testdata/requests" +) + +var ( + generateGolden = flag.Bool("generate-golden", false, + "generate golden files if they do not exist") +) + +type goldenTestCase struct { + Name string + Test func(t *testing.T) tarantool.Request + Request tarantool.Request + Resolver tarantool.SchemaResolver +} + +func (tc goldenTestCase) Execute(t *testing.T) { + t.Helper() + + if tc.Request != nil { + if tc.Test != nil { + require.FailNow(t, "both Test and Request must not be set") + } + + tc.Test = func(t *testing.T) tarantool.Request { + return tc.Request + } + } + if tc.Resolver == nil { + tc.Resolver = &dummySchemaResolver{} + } + + name := path.Join(pathPrefix, tc.Name) + + t.Run(name, func(t *testing.T) { + var out bytes.Buffer + encoder := msgpack.NewEncoder(&out) + + req := tc.Test(t) + require.NotNil(t, req, "failed to create request") + + err := req.Body(&dummySchemaResolver{}, encoder) + require.NoError(t, err, "failed to encode request") + + goldenFileExists := fileExists(name) + generateGoldenIsSet := *generateGolden && !goldenFileExists + + switch { + case !goldenFileExists && generateGoldenIsSet: + t.Logf("writing golden file %s", name) + err := os.WriteFile(name, out.Bytes(), 0644) + require.NoError(t, err, "failed to write golden file", name) + logMsgpackAsJsonConvert(t, out.Bytes()) + case !goldenFileExists && !generateGoldenIsSet: + assert.FailNow(t, "golden file does not exist") + } + + compareGoldenMsgpackAndPrintDiff(t, name, out.Bytes()) + }) +} + +type dummySchemaResolver struct{} + +func interfaceToUint32(in interface{}) (uint32, bool) { + switch val := reflect.ValueOf(in); val.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return uint32(val.Int()), true + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return uint32(val.Uint()), true + default: + return 0, false + } +} + +func (d dummySchemaResolver) ResolveSpace(in interface{}) (uint32, error) { + if num, ok := interfaceToUint32(in); ok { + return num, nil + } + return 0, fmt.Errorf("unexpected space type %T", in) +} + +func (d dummySchemaResolver) ResolveIndex(in interface{}, _ uint32) (uint32, error) { + if in == nil { + return 0, nil + } else if num, ok := interfaceToUint32(in); ok { + return num, nil + } + return 0, fmt.Errorf("unexpected index type %T", in) +} + +func (d dummySchemaResolver) NamesUseSupported() bool { + return true +} + +func TestGolden(t *testing.T) { + precachedUUID := uuid.MustParse("819308aa-f0c1-4b74-9861-c4ab5a266308") + precachedTime := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC) + precachedTuple := []interface{}{1, "args", 3, precachedTime, precachedUUID, 1.2} + + precachedUpdateOps := tarantool.NewOperations(). + Add(1, "test"). + Assign(2, "fest"). + Delete(3, ""). + Insert(4, "insert"). + Splice(5, 6, 7, "splice"). + Subtract(6, "subtract"). + BitwiseAnd(7, 10). + BitwiseOr(8, 11). + BitwiseXor(9, 12) + + testCases := []goldenTestCase{ + { + Name: "commit-raw.msgpack", + Request: tarantool.NewCommitRequest(), + }, + { + Name: "commit-with-sync.msgpack", + Request: tarantool.NewCommitRequest().IsSync(true), + }, + { + Name: "commit-with-sync-false.msgpack", + Request: tarantool.NewCommitRequest().IsSync(false), + }, + { + Name: "begin.msgpack", + Request: tarantool.NewBeginRequest(), + }, + { + Name: "begin-with-txn-isolation.msgpack", + Request: tarantool.NewBeginRequest(). + TxnIsolation(tarantool.ReadCommittedLevel), + }, + { + Name: "begin-with-txn-isolation-is-sync.msgpack", + Request: tarantool.NewBeginRequest(). + TxnIsolation(tarantool.ReadCommittedLevel). + IsSync(true), + }, + { + Name: "begin-with-txn-isolation-is-sync-timeout.msgpack", + Request: tarantool.NewBeginRequest(). + TxnIsolation(tarantool.ReadCommittedLevel). + IsSync(true). + Timeout(2 * time.Second), + }, + { + Name: "rollback.msgpack", + Request: tarantool.NewRollbackRequest(), + }, + { + Name: "ping.msgpack", + Request: tarantool.NewPingRequest(), + }, + { + Name: "call-no-args.msgpack", + Request: tarantool.NewCallRequest("function.name"), + }, + { + Name: "call-with-args.msgpack", + Request: tarantool.NewCallRequest("function.name").Args( + []interface{}{1, 2, 3}, + ), + }, + { + Name: "call-with-args-mixed.msgpack", + Request: tarantool.NewCallRequest("function.name").Args( + []interface{}{1, "args", 3, precachedTime, precachedUUID, 1.2}, + ), + }, + { + Name: "call-with-args-nil.msgpack", + Request: tarantool.NewCallRequest("function.name").Args(nil), + }, + { + Name: "call-with-args-empty-array.msgpack", + Request: tarantool.NewCallRequest("function.name").Args([]int{}), + }, + { + Name: "eval.msgpack", + Request: tarantool.NewEvalRequest("function_name()"), + }, + { + Name: "eval-with-nil.msgpack", + Request: tarantool.NewEvalRequest("function_name()").Args(nil), + }, + { + Name: "eval-with-empty-array.msgpack", + Request: tarantool.NewEvalRequest("function_name()").Args([]int{}), + }, + { + Name: "eval-with-args.msgpack", + Request: tarantool.NewEvalRequest("function_name(...)").Args(precachedTuple), + }, + { + Name: "eval-with-single-number.msgpack", + Request: tarantool.NewEvalRequest("function_name()").Args(1), + }, + { + Name: "delete-raw.msgpack", + Request: tarantool.NewDeleteRequest("table_name"), + }, + { + Name: "delete-snumber-inumber.msgpack", + Request: tarantool.NewDeleteRequest(246). + Index(123).Key([]interface{}{123}), + }, + { + Name: "delete-snumber-iname.msgpack", + Request: tarantool.NewDeleteRequest(246). + Index("index_name").Key([]interface{}{123}), + }, + { + Name: "delete-sname-inumber.msgpack", + Request: tarantool.NewDeleteRequest("table_name"). + Index(123).Key([]interface{}{123}), + }, + { + Name: "delete-sname-iname.msgpack", + Request: tarantool.NewDeleteRequest("table_name"). + Index("index_name").Key([]interface{}{123}), + }, + { + Name: "replace-sname.msgpack", + Request: tarantool.NewReplaceRequest("table_name"). + Tuple(precachedTuple), + }, + { + Name: "replace-snumber.msgpack", + Request: tarantool.NewReplaceRequest(123). + Tuple(precachedTuple), + }, + { + Name: "insert-sname.msgpack", + Request: tarantool.NewReplaceRequest("table_name"). + Tuple(precachedTuple), + }, + { + Name: "insert-snumber.msgpack", + Request: tarantool.NewReplaceRequest(123). + Tuple(precachedTuple), + }, + { + Name: "call16.msgpack", + Request: tarantool.NewCall16Request("function.name"), + }, + { + Name: "call16-with-args.msgpack", + Request: tarantool.NewCall16Request("function.name"). + Args(precachedTuple), + }, + { + Name: "call16-with-args-nil.msgpack", + Request: tarantool.NewCall16Request("function.name").Args(nil), + }, + { + Name: "call17.msgpack", + Request: tarantool.NewCall17Request("function.name"), + }, + { + Name: "call17-with-args-nil.msgpack", + Request: tarantool.NewCall17Request("function.name").Args(nil), + }, + { + Name: "call17-with-args.msgpack", + Request: tarantool.NewCall17Request("function.name"). + Args(precachedTuple), + }, + { + Name: "update.msgpack", + Request: tarantool.NewUpdateRequest("table_name"), + }, + { + Name: "update-snumber-iname.msgpack", + Request: tarantool.NewUpdateRequest(123). + Index("index_name").Key([]interface{}{123}). + Operations(precachedUpdateOps), + }, + { + Name: "update-sname-iname.msgpack", + Request: tarantool.NewUpdateRequest("table_name"). + Index("index_name").Key([]interface{}{123}). + Operations(precachedUpdateOps), + }, + { + Name: "update-sname-inumber.msgpack", + Request: tarantool.NewUpdateRequest("table_name"). + Index(123).Key([]interface{}{123}). + Operations(precachedUpdateOps), + }, + { + Name: "upsert.msgpack", + Request: tarantool.NewUpsertRequest("table_name"), + }, + { + Name: "upsert-snumber.msgpack", + Request: tarantool.NewUpsertRequest(123). + Operations(precachedUpdateOps). + Tuple(precachedTuple), + }, + { + Name: "upsert-sname.msgpack", + Request: tarantool.NewUpsertRequest("table_name"). + Operations(precachedUpdateOps). + Tuple(precachedTuple), + }, + { + Name: "select", + Request: tarantool.NewSelectRequest("table_name"), + }, + { + Name: "select-sname-iname.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + Index("index_name"), + }, + { + Name: "select-sname-inumber.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + Index(123), + }, + { + Name: "select-snumber-iname.msgpack", + Request: tarantool.NewSelectRequest(123). + Index("index_name"), + }, + { + Name: "select-snumber-inumber.msgpack", + Request: tarantool.NewSelectRequest(123). + Index(123), + }, + { + Name: "select-with-key.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + Key(precachedTuple), + }, + { + Name: "select-key-sname-iname.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + Index("index_name").Key(precachedTuple), + }, + { + Name: "select-key-sname-inumber.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + Index(123).Key(precachedTuple), + }, + { + Name: "select-key-snumber-iname.msgpack", + Request: tarantool.NewSelectRequest(123). + Index("index_name").Key(precachedTuple), + }, + { + Name: "select-key-snumber-inumber.msgpack", + Request: tarantool.NewSelectRequest(123). + Index(123).Key(precachedTuple), + }, + { + Name: "select-with-optionals.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + Offset(123).Limit(123).Iterator(tarantool.IterGe). + FetchPos(true), + }, + { + Name: "select-with-after.msgpack", + Request: tarantool.NewSelectRequest("table_name"). + After(precachedTuple).Limit(123).Iterator(tarantool.IterGe). + Key(precachedTuple), + }, + } + + for _, tc := range testCases { + tc.Execute(t) + } +} diff --git a/request_test.go b/request_test.go index 62baffb32..43e22d311 100644 --- a/request_test.go +++ b/request_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tarantool/go-iproto" "github.com/vmihailenco/msgpack/v5" - "github.com/tarantool/go-iproto" . "github.com/tarantool/go-tarantool/v2" ) diff --git a/testdata/requests/begin-with-txn-isolation-is-sync-timeout.msgpack b/testdata/requests/begin-with-txn-isolation-is-sync-timeout.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..dc04ebcd0833c9e2df8b6c3252ce05075497dd66 GIT binary patch literal 15 RcmZn;JMF*#0g;S}hXEX`17iRH literal 0 HcmV?d00001 diff --git a/testdata/requests/begin-with-txn-isolation-is-sync.msgpack b/testdata/requests/begin-with-txn-isolation-is-sync.msgpack new file mode 100644 index 000000000..962d8b233 --- /dev/null +++ b/testdata/requests/begin-with-txn-isolation-is-sync.msgpack @@ -0,0 +1 @@ +‚Yaà \ No newline at end of file diff --git a/testdata/requests/begin-with-txn-isolation.msgpack b/testdata/requests/begin-with-txn-isolation.msgpack new file mode 100644 index 000000000..bce57fe8c --- /dev/null +++ b/testdata/requests/begin-with-txn-isolation.msgpack @@ -0,0 +1 @@ +Y \ No newline at end of file diff --git a/testdata/requests/begin.msgpack b/testdata/requests/begin.msgpack new file mode 100644 index 000000000..5416677bc --- /dev/null +++ b/testdata/requests/begin.msgpack @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/testdata/requests/call-no-args.msgpack b/testdata/requests/call-no-args.msgpack new file mode 100644 index 000000000..17e7abbb0 --- /dev/null +++ b/testdata/requests/call-no-args.msgpack @@ -0,0 +1 @@ +‚"­function.name! \ No newline at end of file diff --git a/testdata/requests/call-with-args-empty-array.msgpack b/testdata/requests/call-with-args-empty-array.msgpack new file mode 100644 index 000000000..17e7abbb0 --- /dev/null +++ b/testdata/requests/call-with-args-empty-array.msgpack @@ -0,0 +1 @@ +‚"­function.name! \ No newline at end of file diff --git a/testdata/requests/call-with-args-mixed.msgpack b/testdata/requests/call-with-args-mixed.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..8a10ddcfac0a65f07edaf0f80db226e65c142c95 GIT binary patch literal 58 zcmZotTANmymt2yWpQo3Xn479Njd4k0QF<}+wg0J;7#fZUG*0GN_2Hm*$&AD!tE1GC LIZoSuHU$e=I*06-Q7RR910 literal 0 HcmV?d00001 diff --git a/testdata/requests/delete-sname-iname.msgpack b/testdata/requests/delete-sname-iname.msgpack new file mode 100644 index 000000000..49acbef2f --- /dev/null +++ b/testdata/requests/delete-sname-iname.msgpack @@ -0,0 +1 @@ +ƒ^ªtable_name_ªindex_name ‘{ \ No newline at end of file diff --git a/testdata/requests/delete-sname-inumber.msgpack b/testdata/requests/delete-sname-inumber.msgpack new file mode 100644 index 000000000..9390f6e9b --- /dev/null +++ b/testdata/requests/delete-sname-inumber.msgpack @@ -0,0 +1 @@ +ƒ^ªtable_name{ ‘{ \ No newline at end of file diff --git a/testdata/requests/delete-snumber-iname.msgpack b/testdata/requests/delete-snumber-iname.msgpack new file mode 100644 index 000000000..5805ea28e --- /dev/null +++ b/testdata/requests/delete-snumber-iname.msgpack @@ -0,0 +1 @@ +ƒÌö_ªindex_name ‘{ \ No newline at end of file diff --git a/testdata/requests/delete-snumber-inumber.msgpack b/testdata/requests/delete-snumber-inumber.msgpack new file mode 100644 index 000000000..39c85022e --- /dev/null +++ b/testdata/requests/delete-snumber-inumber.msgpack @@ -0,0 +1 @@ +ƒÌö{ ‘{ \ No newline at end of file diff --git a/testdata/requests/delete.msgpack b/testdata/requests/delete.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..8d001f87ccaa5a3cada8a17d3c339e8cce829c4e GIT binary patch literal 17 YcmZpUTUC;nl#?2tmzbL>$e=I*06-Q7RR910 literal 0 HcmV?d00001 diff --git a/testdata/requests/eval-with-args.msgpack b/testdata/requests/eval-with-args.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..6ab7b9953b7768ac496ff5038d6c8abc141df9f7 GIT binary patch literal 63 zcmZot-;`FGmt2yWpBJB(n47Ahr>Cc>IE`^hVo`cA^R@q}lNcI~2sBRSSoPtccgc*z QBdep-k~vP>e>MgK04?7cfdBvi literal 0 HcmV?d00001 diff --git a/testdata/requests/eval-with-empty-array.msgpack b/testdata/requests/eval-with-empty-array.msgpack new file mode 100644 index 000000000..152e20ef1 --- /dev/null +++ b/testdata/requests/eval-with-empty-array.msgpack @@ -0,0 +1 @@ +‚'¯function_name()! \ No newline at end of file diff --git a/testdata/requests/eval-with-nil.msgpack b/testdata/requests/eval-with-nil.msgpack new file mode 100644 index 000000000..152e20ef1 --- /dev/null +++ b/testdata/requests/eval-with-nil.msgpack @@ -0,0 +1 @@ +‚'¯function_name()! \ No newline at end of file diff --git a/testdata/requests/eval-with-single-number.msgpack b/testdata/requests/eval-with-single-number.msgpack new file mode 100644 index 000000000..0d75cc10e --- /dev/null +++ b/testdata/requests/eval-with-single-number.msgpack @@ -0,0 +1 @@ +‚'¯function_name()! \ No newline at end of file diff --git a/testdata/requests/eval.msgpack b/testdata/requests/eval.msgpack new file mode 100644 index 000000000..152e20ef1 --- /dev/null +++ b/testdata/requests/eval.msgpack @@ -0,0 +1 @@ +‚'¯function_name()! \ No newline at end of file diff --git a/testdata/requests/insert-sname.msgpack b/testdata/requests/insert-sname.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..6e5f221a7afe588db3063379c99fc5c6f78b9886 GIT binary patch literal 55 zcmZpQTUC;nl#?2tmzbNXIE`^hVo`cA^R@q}lNcI~2sBRSSoPtccgc*zBdep-k~vP> Ie>MgK0HPBYcK`qY literal 0 HcmV?d00001 diff --git a/testdata/requests/insert-snumber.msgpack b/testdata/requests/insert-snumber.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..2fd7d3af3bda56bbc3cb846055247fc4dc0f0ff7 GIT binary patch literal 45 ycmZn?s8*cDxFoSCy_osh|I|qg4MzkTCv&X&aL~JCM&gmxQEJH?r|mx*g8=}&u@dqC literal 0 HcmV?d00001 diff --git a/testdata/requests/ping.msgpack b/testdata/requests/ping.msgpack new file mode 100644 index 000000000..5416677bc --- /dev/null +++ b/testdata/requests/ping.msgpack @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/testdata/requests/replace-sname.msgpack b/testdata/requests/replace-sname.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..6e5f221a7afe588db3063379c99fc5c6f78b9886 GIT binary patch literal 55 zcmZpQTUC;nl#?2tmzbNXIE`^hVo`cA^R@q}lNcI~2sBRSSoPtccgc*zBdep-k~vP> Ie>MgK0HPBYcK`qY literal 0 HcmV?d00001 diff --git a/testdata/requests/replace-snumber.msgpack b/testdata/requests/replace-snumber.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..2fd7d3af3bda56bbc3cb846055247fc4dc0f0ff7 GIT binary patch literal 45 ycmZn?s8*cDxFoSCy_osh|I|qg4MzkTCv&X&aL~JCM&gmxQEJH?r|mx*g8=}&u@dqC literal 0 HcmV?d00001 diff --git a/testdata/requests/rollback.msgpack b/testdata/requests/rollback.msgpack new file mode 100644 index 000000000..5416677bc --- /dev/null +++ b/testdata/requests/rollback.msgpack @@ -0,0 +1 @@ +€ \ No newline at end of file diff --git a/testdata/requests/select b/testdata/requests/select new file mode 100644 index 0000000000000000000000000000000000000000..ebed86cadbed1b6f2786b7f3f36b8bcec29d26a5 GIT binary patch literal 27 hcmZn@VG?E#I`E=ep(FJ`{>KXnpA!x4eT a$sDUb9P}=kk$7Zvlv*;!Y5UK{U;qF=rXijH literal 0 HcmV?d00001 diff --git a/testdata/requests/select-key-sname-inumber.msgpack b/testdata/requests/select-key-sname-inumber.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..e8cdb0bd9a355f5a0a62b6f7cb98bf3390b3cd43 GIT binary patch literal 67 zcmZn@VGw2zI`L|5jj??y^jllo_^GzKI literal 0 HcmV?d00001 diff --git a/testdata/requests/select-key-snumber-iname.msgpack b/testdata/requests/select-key-snumber-iname.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..f686f9afc0de27646c6387c5998766dca86a6a99 GIT binary patch literal 67 zcmZn@VGw2zI`bEe=B6r4V_cG0lwQny?SJYdhK3^ojgvW6eK_b{ TG9&TG>L|5jj??y^jllo_^0OTo literal 0 HcmV?d00001 diff --git a/testdata/requests/select-key-snumber-inumber.msgpack b/testdata/requests/select-key-snumber-inumber.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..29ea666d4ed4e5d7caee9642df0ca50c3d834099 GIT binary patch literal 57 zcmZn@VGw2zI`bEe=B6r4005*A3+Mm< literal 0 HcmV?d00001 diff --git a/testdata/requests/select-snumber-inumber.msgpack b/testdata/requests/select-snumber-inumber.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..8470a2045cb539f13685f64fb15313cbbc754602 GIT binary patch literal 17 XcmZn@VG?E#I`e>MgKeWFzY0BdF{Hvj+t literal 0 HcmV?d00001 diff --git a/testdata/requests/select-with-key.msgpack b/testdata/requests/select-with-key.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..f0976da10db6c07d99e4da5945d9d66d542c9995 GIT binary patch literal 67 zcmZn@VGw2zI`L|5jj??y^jllo_-lQCk literal 0 HcmV?d00001 diff --git a/testdata/requests/select-with-optionals.msgpack b/testdata/requests/select-with-optionals.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..4915ece9768e869248787828758605d84dcb87b7 GIT binary patch literal 25 gcmZn{VHK_xs*YP#l9-f}8lRV#n<~hlFhTw>0BO<)ZvX%Q literal 0 HcmV?d00001 diff --git a/testdata/requests/update-sname-iname.msgpack b/testdata/requests/update-sname-iname.msgpack new file mode 100644 index 000000000..b085c995b --- /dev/null +++ b/testdata/requests/update-sname-iname.msgpack @@ -0,0 +1,2 @@ +„^ªtable_name_ªindex_name ‘{!™“¡+¤test“¡=¤fest“¡# “¡!¦insert•¡:¦splice“¡-¨subtract“¡& +“¡| “¡^ \ No newline at end of file diff --git a/testdata/requests/update-sname-inumber.msgpack b/testdata/requests/update-sname-inumber.msgpack new file mode 100644 index 000000000..f603ddf34 --- /dev/null +++ b/testdata/requests/update-sname-inumber.msgpack @@ -0,0 +1,2 @@ +„^ªtable_name{ ‘{!™“¡+¤test“¡=¤fest“¡# “¡!¦insert•¡:¦splice“¡-¨subtract“¡& +“¡| “¡^ \ No newline at end of file diff --git a/testdata/requests/update-snumber-iname.msgpack b/testdata/requests/update-snumber-iname.msgpack new file mode 100644 index 000000000..cd3ec4317 --- /dev/null +++ b/testdata/requests/update-snumber-iname.msgpack @@ -0,0 +1,2 @@ +„{_ªindex_name ‘{!™“¡+¤test“¡=¤fest“¡# “¡!¦insert•¡:¦splice“¡-¨subtract“¡& +“¡| “¡^ \ No newline at end of file diff --git a/testdata/requests/update.msgpack b/testdata/requests/update.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..3749bbcade764e358229730f2e728decc0923fa4 GIT binary patch literal 19 acmZpPTUC;nl#?2tmzbL>$e=JmaRLBMr3VK9 literal 0 HcmV?d00001 diff --git a/testdata/requests/upsert-sname.msgpack b/testdata/requests/upsert-sname.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..3620cbc1e2b178779e45e0fdf38d8fb3cec25f8e GIT binary patch literal 132 zcmZpUTUC;nl#?2tmzbNXIE`^hVo`cA^R@q}lNcI~2sBRSSoPtccgc*zBdep-k~vP> ze>MgKjhT}dYBMe=Ni8m!ywH|uNg9};%)DUoLPeHknR&&jMI}=gTCuXRFDov{$xKe2 gyik{IMR93TNl{`lP>UKn*W`sY9Nd!^#&Plh0BdtKNB{r; literal 0 HcmV?d00001 diff --git a/testdata/requests/upsert-snumber.msgpack b/testdata/requests/upsert-snumber.msgpack new file mode 100644 index 0000000000000000000000000000000000000000..6e34b0c2fe7ceb0895e1d6e1c9d2cf8b1dbee621 GIT binary patch literal 122 zcmZn`s8*cDxFoSCy_osh|I|qg4MzkTCv&X&aL~JCM&gmxQEJH?r|mx*gMr4($qTg^ zmz1OymrP!0%d{j7%ur@tFnOUO%d*V8;?$y&sSB-G+1QsA7vy9nr%qm|%eJDpG^wO0 VF&U^ujh$=q!Ws_l$qVB+c>pT+Fv9=< literal 0 HcmV?d00001 diff --git a/testdata/requests/upsert.msgpack b/testdata/requests/upsert.msgpack new file mode 100644 index 000000000..06a3800f8 --- /dev/null +++ b/testdata/requests/upsert.msgpack @@ -0,0 +1 @@ +ƒ^ªtable_name!( \ No newline at end of file