forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: update all
Update
and Upsert
requests
`Op` struct made private. Change all `Upsert` and `Update` requests to accept `*tarantool.Operations` as `ops` parameters instead of `interface{}`. Closes #348
- Loading branch information
1 parent
a5de8f3
commit 6225ec4
Showing
16 changed files
with
281 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package tarantool_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/vmihailenco/msgpack/v5" | ||
|
||
"github.com/tarantool/go-tarantool/v2" | ||
) | ||
|
||
func TestOperations_EncodeMsgpack(t *testing.T) { | ||
ops := tarantool.NewOperations(). | ||
Add(1, 2). | ||
Subtract(1, 2). | ||
BitwiseAnd(1, 2). | ||
BitwiseOr(1, 2). | ||
BitwiseXor(1, 2). | ||
Splice(1, 2, 3, "a"). | ||
Insert(1, 2). | ||
Delete(1, 2). | ||
Assign(1, 2) | ||
refOps := []interface{}{ | ||
[]interface{}{"+", 1, 2}, | ||
[]interface{}{"-", 1, 2}, | ||
[]interface{}{"&", 1, 2}, | ||
[]interface{}{"|", 1, 2}, | ||
[]interface{}{"^", 1, 2}, | ||
[]interface{}{":", 1, 2, 3, "a"}, | ||
[]interface{}{"!", 1, 2}, | ||
[]interface{}{"#", 1, 2}, | ||
[]interface{}{"=", 1, 2}, | ||
} | ||
|
||
var refBuf bytes.Buffer | ||
encRef := msgpack.NewEncoder(&refBuf) | ||
if err := encRef.Encode(refOps); err != nil { | ||
t.Errorf("error while encoding: %v", err.Error()) | ||
} | ||
|
||
var buf bytes.Buffer | ||
enc := msgpack.NewEncoder(&buf) | ||
|
||
if err := enc.Encode(ops); 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()) | ||
} | ||
} |
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,123 @@ | ||
package crud_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/vmihailenco/msgpack/v5" | ||
|
||
"github.com/tarantool/go-tarantool/v2/crud" | ||
) | ||
|
||
func TestOperation_EncodeMsgpack(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
op crud.Operation | ||
ref []interface{} | ||
}{ | ||
{ | ||
"Add", | ||
crud.Operation{ | ||
Operator: crud.Add, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"+", 1, 2}, | ||
}, | ||
{ | ||
"Sub", | ||
crud.Operation{ | ||
Operator: crud.Sub, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"-", 1, 2}, | ||
}, | ||
{ | ||
"And", | ||
crud.Operation{ | ||
Operator: crud.And, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"&", 1, 2}, | ||
}, | ||
{ | ||
"Or", | ||
crud.Operation{ | ||
Operator: crud.Or, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"|", 1, 2}, | ||
}, | ||
{ | ||
"Xor", | ||
crud.Operation{ | ||
Operator: crud.Xor, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"^", 1, 2}, | ||
}, | ||
{ | ||
"Splice", | ||
crud.Operation{ | ||
Operator: crud.Splice, | ||
Field: 1, | ||
Pos: 2, | ||
Len: 3, | ||
Replace: "a", | ||
}, | ||
[]interface{}{":", 1, 2, 3, "a"}, | ||
}, | ||
{ | ||
"Insert", | ||
crud.Operation{ | ||
Operator: crud.Insert, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"!", 1, 2}, | ||
}, | ||
{ | ||
"Delete", | ||
crud.Operation{ | ||
Operator: crud.Delete, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"#", 1, 2}, | ||
}, | ||
{ | ||
"Assign", | ||
crud.Operation{ | ||
Operator: crud.Assign, | ||
Field: 1, | ||
Value: 2, | ||
}, | ||
[]interface{}{"=", 1, 2}, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
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()) | ||
} | ||
|
||
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()) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.