forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crud: support
operation_data
field in errors
This patch adds `operation_data` decoding for the `crud.Error`. The `operation_data` type is determined as `rowType` in `crud.Result`. Also, according to [1], an error can contain one of the following: - an error - an array of errors - nil So the error decoding logic has been modified to consider each case, in order to avoid comparing an error to nil. 1. https://github.com/tarantool/crud/tree/master#api Closes #330
- Loading branch information
1 parent
b17735b
commit d8df65d
Showing
5 changed files
with
160 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package crud_test | ||
|
||
import ( | ||
"bytes" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tarantool/go-tarantool/v2/crud" | ||
"github.com/vmihailenco/msgpack/v5" | ||
) | ||
|
||
func TestResult_DecodeMsgpack(t *testing.T) { | ||
sampleCrudResponse := []interface{}{ | ||
map[string]interface{}{ | ||
"rows": []interface{}{"1", "2", "3"}, | ||
}, | ||
nil, | ||
} | ||
responses := []interface{}{sampleCrudResponse, sampleCrudResponse} | ||
|
||
b := bytes.NewBuffer([]byte{}) | ||
enc := msgpack.NewEncoder(b) | ||
err := enc.Encode(responses) | ||
require.NoError(t, err) | ||
|
||
var results []crud.Result | ||
decoder := msgpack.NewDecoder(b) | ||
err = decoder.DecodeValue(reflect.ValueOf(&results)) | ||
require.NoError(t, err) | ||
require.Equal(t, results[0].Rows, []interface{}{"1", "2", "3"}) | ||
require.Equal(t, results[1].Rows, []interface{}{"1", "2", "3"}) | ||
} |