From 8c03e584c182218c84bebc8af23c70fb0cd203d4 Mon Sep 17 00:00:00 2001 From: Shobhit Gupta Date: Wed, 3 Oct 2018 13:04:37 -0700 Subject: MM-11863 Add KVList method (#9467) * Add KVList method * Add KVList method Add KVList method * Add pagination support * Change offset, limit to page, perPage * Rename constant --- app/plugin_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'app/plugin_test.go') diff --git a/app/plugin_test.go b/app/plugin_test.go index c051324a7..8dcae9b16 100644 --- a/app/plugin_test.go +++ b/app/plugin_test.go @@ -5,6 +5,8 @@ package app import ( "bytes" + "crypto/sha256" + "encoding/base64" "io/ioutil" "net/http" "net/http/httptest" @@ -17,6 +19,11 @@ import ( "github.com/stretchr/testify/require" ) +func getHashedKey(key string) string { + hash := sha256.New() + hash.Write([]byte(key)) + return base64.StdEncoding.EncodeToString(hash.Sum(nil)) +} func TestPluginKeyValueStore(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() @@ -40,6 +47,41 @@ func TestPluginKeyValueStore(t *testing.T) { assert.Nil(t, th.App.DeletePluginKey(pluginId, "intkey")) assert.Nil(t, th.App.DeletePluginKey(pluginId, "postkey")) assert.Nil(t, th.App.DeletePluginKey(pluginId, "notrealkey")) + + // Test ListKeys + assert.Nil(t, th.App.SetPluginKey(pluginId, "key2", []byte("test"))) + hashedKey := getHashedKey("key") + hashedKey2 := getHashedKey("key2") + list, err := th.App.ListPluginKeys(pluginId, 0, 1) + assert.Nil(t, err) + assert.Equal(t, 1, len(list)) + assert.Equal(t, hashedKey, list[0]) + + list, err = th.App.ListPluginKeys(pluginId, 1, 1) + assert.Nil(t, err) + assert.Equal(t, 1, len(list)) + assert.Equal(t, hashedKey2, list[0]) + + //List Keys bad input + list, err = th.App.ListPluginKeys(pluginId, 0, 0) + assert.Nil(t, err) + assert.Equal(t, 2, len(list)) + + list, err = th.App.ListPluginKeys(pluginId, 0, -1) + assert.Nil(t, err) + assert.Equal(t, 2, len(list)) + + list, err = th.App.ListPluginKeys(pluginId, -1, 1) + assert.Nil(t, err) + assert.Equal(t, 1, len(list)) + + list, err = th.App.ListPluginKeys(pluginId, -1, 0) + assert.Nil(t, err) + assert.Equal(t, 2, len(list)) + + list, err = th.App.ListPluginKeys(pluginId, 2, 2) + assert.Nil(t, err) + assert.Equal(t, 0, len(list)) } func TestServePluginRequest(t *testing.T) { -- cgit v1.2.3-1-g7c22