[MM-20353] Change KVSetWithOptions to accept a byte slice (#13213)

* Drop EncodeJSON from PluginKVSetOptions

* Add unit tests for KVSetWithOptions with nil values
Этот коммит содержится в:
Ben Schumacher
2019-12-03 10:46:15 +01:00
коммит произвёл GitHub
родитель 3543fcce6c
Коммит d0d6ce0a70
11 изменённых файлов: 104 добавлений и 161 удалений

Просмотреть файл

@@ -758,13 +758,12 @@ type API interface {
KVCompareAndDelete(key string, oldValue []byte) (bool, *model.AppError)
// KVSetWithOptions stores a key-value pair, unique per plugin, according to the given options.
// If options.EncodeJSON is not true, the type of newValue must be of type []byte.
// Returns (false, err) if DB error occurred
// Returns (false, nil) if the value was not set
// Returns (true, nil) if the value was set
//
// Minimum server version: 5.18
KVSetWithOptions(key string, newValue interface{}, options model.PluginKVSetOptions) (bool, *model.AppError)
// Minimum server version: 5.20
KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
// KVSet stores a key-value pair with an expiry time, unique per plugin.
//

Просмотреть файл

@@ -3698,7 +3698,7 @@ func (s *apiRPCServer) KVCompareAndDelete(args *Z_KVCompareAndDeleteArgs, return
type Z_KVSetWithOptionsArgs struct {
A string
B interface{}
B []byte
C model.PluginKVSetOptions
}
@@ -3707,8 +3707,8 @@ type Z_KVSetWithOptionsReturns struct {
B *model.AppError
}
func (g *apiRPCClient) KVSetWithOptions(key string, newValue interface{}, options model.PluginKVSetOptions) (bool, *model.AppError) {
_args := &Z_KVSetWithOptionsArgs{key, newValue, options}
func (g *apiRPCClient) KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) {
_args := &Z_KVSetWithOptionsArgs{key, value, options}
_returns := &Z_KVSetWithOptionsReturns{}
if err := g.client.Call("Plugin.KVSetWithOptions", _args, _returns); err != nil {
log.Printf("RPC call to KVSetWithOptions API failed: %s", err.Error())
@@ -3718,7 +3718,7 @@ func (g *apiRPCClient) KVSetWithOptions(key string, newValue interface{}, option
func (s *apiRPCServer) KVSetWithOptions(args *Z_KVSetWithOptionsArgs, returns *Z_KVSetWithOptionsReturns) error {
if hook, ok := s.impl.(interface {
KVSetWithOptions(key string, newValue interface{}, options model.PluginKVSetOptions) (bool, *model.AppError)
KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
}); ok {
returns.A, returns.B = hook.KVSetWithOptions(args.A, args.B, args.C)
} else {

Просмотреть файл

@@ -2210,20 +2210,20 @@ func (_m *API) KVSetWithExpiry(key string, value []byte, expireInSeconds int64)
return r0
}
// KVSetWithOptions provides a mock function with given fields: key, newValue, options
func (_m *API) KVSetWithOptions(key string, newValue interface{}, options model.PluginKVSetOptions) (bool, *model.AppError) {
ret := _m.Called(key, newValue, options)
// KVSetWithOptions provides a mock function with given fields: key, value, options
func (_m *API) KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) {
ret := _m.Called(key, value, options)
var r0 bool
if rf, ok := ret.Get(0).(func(string, interface{}, model.PluginKVSetOptions) bool); ok {
r0 = rf(key, newValue, options)
if rf, ok := ret.Get(0).(func(string, []byte, model.PluginKVSetOptions) bool); ok {
r0 = rf(key, value, options)
} else {
r0 = ret.Get(0).(bool)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, interface{}, model.PluginKVSetOptions) *model.AppError); ok {
r1 = rf(key, newValue, options)
if rf, ok := ret.Get(1).(func(string, []byte, model.PluginKVSetOptions) *model.AppError); ok {
r1 = rf(key, value, options)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)