Add KV helper methods to Helpers interface (#11307)

* Add KV helper methods to Helpers interface

* Address code-review comments, add unit tests

* Update documentation for KVCompareAndSetJSON.

* Update assertions for helpers_bots_test.go

* Fix assertion not called name in test.
Этот коммит содержится в:
Zachary Romero
2019-06-28 13:27:46 +00:00
коммит произвёл Ali Farooq
родитель ac4019afe5
Коммит 46f2b18e4f
4 изменённых файлов: 296 добавлений и 1 удалений

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

@@ -6,10 +6,26 @@ package plugin
import "github.com/mattermost/mattermost-server/model"
type Helpers interface {
// EnsureBot ether returns an existing bot user or creates a bot user with
// EnsureBot either returns an existing bot user or creates a bot user with
// the specifications of the passed bot.
// Returns the id of the bot created or existing.
EnsureBot(bot *model.Bot) (string, error)
// KVGetJSON retrievs a value based on the key.
KVGetJSON(key string, value interface{}) error
// KVSetJSON stores a key-value pair.
KVSetJSON(key string, value interface{}) error
// KVCompareAndSetJSON updates a key-value pair if the current
// value is equal to oldValue.
// Returns (false, err) if DB/marshal/unmarshal error occurred
// Returns (false, nil) if current value != old value
// Returns (true, nil) if current value == old value or new key is inserted
KVCompareAndSetJSON(key string, oldValue interface{}, newValue interface{}) (bool, error)
// KVSetWithExpiryJSON stores a key-value pair with an expiry time.
KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error
}
type HelpersImpl struct {