[Partial Fix #16623]: Fix initialism errors in codebase. (#16979)

Automatic Merge
Этот коммит содержится в:
SimonSimonB
2021-02-25 20:22:27 +01:00
коммит произвёл GitHub
родитель 0ba28a712a
Коммит 6fa4c8b8bd
36 изменённых файлов: 875 добавлений и 875 удалений

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

@@ -37,38 +37,38 @@ func TestPluginKeyValueStore(t *testing.T) {
th := Setup(t)
defer th.TearDown()
pluginId := "testpluginid"
pluginID := "testpluginid"
defer func() {
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key"))
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key2"))
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key3"))
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key4"))
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key"))
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key2"))
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key3"))
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key4"))
}()
assert.Nil(t, th.App.SetPluginKey(pluginId, "key", []byte("test")))
ret, err := th.App.GetPluginKey(pluginId, "key")
assert.Nil(t, th.App.SetPluginKey(pluginID, "key", []byte("test")))
ret, err := th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte("test"), ret)
// Test inserting over existing entries
assert.Nil(t, th.App.SetPluginKey(pluginId, "key", []byte("test2")))
ret, err = th.App.GetPluginKey(pluginId, "key")
assert.Nil(t, th.App.SetPluginKey(pluginID, "key", []byte("test2")))
ret, err = th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte("test2"), ret)
// Test getting non-existent key
ret, err = th.App.GetPluginKey(pluginId, "notakey")
ret, err = th.App.GetPluginKey(pluginID, "notakey")
assert.Nil(t, err)
assert.Nil(t, ret)
// Test deleting non-existent keys.
assert.Nil(t, th.App.DeletePluginKey(pluginId, "notrealkey"))
assert.Nil(t, th.App.DeletePluginKey(pluginID, "notrealkey"))
// Verify behaviour for the old approach that involved storing the hashed keys.
hashedKey2 := getHashedKey("key2")
kv := &model.PluginKeyValue{
PluginId: pluginId,
PluginId: pluginID,
Key: hashedKey2,
Value: []byte("test"),
ExpireAt: 0,
@@ -78,57 +78,57 @@ func TestPluginKeyValueStore(t *testing.T) {
assert.NoError(t, nErr)
// Test fetch by keyname (this key does not exist but hashed key will be used for lookup)
ret, err = th.App.GetPluginKey(pluginId, "key2")
ret, err = th.App.GetPluginKey(pluginID, "key2")
assert.Nil(t, err)
assert.Equal(t, kv.Value, ret)
// Test fetch by hashed keyname
ret, err = th.App.GetPluginKey(pluginId, hashedKey2)
ret, err = th.App.GetPluginKey(pluginID, hashedKey2)
assert.Nil(t, err)
assert.Equal(t, kv.Value, ret)
// Test ListKeys
assert.Nil(t, th.App.SetPluginKey(pluginId, "key3", []byte("test3")))
assert.Nil(t, th.App.SetPluginKey(pluginId, "key4", []byte("test4")))
assert.Nil(t, th.App.SetPluginKey(pluginID, "key3", []byte("test3")))
assert.Nil(t, th.App.SetPluginKey(pluginID, "key4", []byte("test4")))
list, err := th.App.ListPluginKeys(pluginId, 0, 1)
list, err := th.App.ListPluginKeys(pluginID, 0, 1)
assert.Nil(t, err)
assert.Equal(t, []string{"key"}, list)
list, err = th.App.ListPluginKeys(pluginId, 1, 1)
list, err = th.App.ListPluginKeys(pluginID, 1, 1)
assert.Nil(t, err)
assert.Equal(t, []string{"key3"}, list)
list, err = th.App.ListPluginKeys(pluginId, 0, 4)
list, err = th.App.ListPluginKeys(pluginID, 0, 4)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, 0, 2)
list, err = th.App.ListPluginKeys(pluginID, 0, 2)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3"}, list)
list, err = th.App.ListPluginKeys(pluginId, 1, 2)
list, err = th.App.ListPluginKeys(pluginID, 1, 2)
assert.Nil(t, err)
assert.Equal(t, []string{"key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, 2, 2)
list, err = th.App.ListPluginKeys(pluginID, 2, 2)
assert.Nil(t, err)
assert.Equal(t, []string{}, list)
// List Keys bad input
list, err = th.App.ListPluginKeys(pluginId, 0, 0)
list, err = th.App.ListPluginKeys(pluginID, 0, 0)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, 0, -1)
list, err = th.App.ListPluginKeys(pluginID, 0, -1)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, -1, 1)
list, err = th.App.ListPluginKeys(pluginID, -1, 1)
assert.Nil(t, err)
assert.Equal(t, []string{"key"}, list)
list, err = th.App.ListPluginKeys(pluginId, -1, 0)
list, err = th.App.ListPluginKeys(pluginID, -1, 0)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
}
@@ -137,72 +137,72 @@ func TestPluginKeyValueStoreCompareAndSet(t *testing.T) {
th := Setup(t)
defer th.TearDown()
pluginId := "testpluginid"
pluginID := "testpluginid"
defer func() {
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key"))
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key"))
}()
// Set using Set api for key2
assert.Nil(t, th.App.SetPluginKey(pluginId, "key2", []byte("test")))
ret, err := th.App.GetPluginKey(pluginId, "key2")
assert.Nil(t, th.App.SetPluginKey(pluginID, "key2", []byte("test")))
ret, err := th.App.GetPluginKey(pluginID, "key2")
assert.Nil(t, err)
assert.Equal(t, []byte("test"), ret)
// Attempt to insert value for key2
updated, err := th.App.CompareAndSetPluginKey(pluginId, "key2", nil, []byte("test2"))
updated, err := th.App.CompareAndSetPluginKey(pluginID, "key2", nil, []byte("test2"))
assert.Nil(t, err)
assert.False(t, updated)
ret, err = th.App.GetPluginKey(pluginId, "key2")
ret, err = th.App.GetPluginKey(pluginID, "key2")
assert.Nil(t, err)
assert.Equal(t, []byte("test"), ret)
// Insert new value for key
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", nil, []byte("test"))
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", nil, []byte("test"))
assert.Nil(t, err)
assert.True(t, updated)
ret, err = th.App.GetPluginKey(pluginId, "key")
ret, err = th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte("test"), ret)
// Should fail to insert again
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", nil, []byte("test3"))
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", nil, []byte("test3"))
assert.Nil(t, err)
assert.False(t, updated)
ret, err = th.App.GetPluginKey(pluginId, "key")
ret, err = th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte("test"), ret)
// Test updating using incorrect old value
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", []byte("oldvalue"), []byte("test3"))
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", []byte("oldvalue"), []byte("test3"))
assert.Nil(t, err)
assert.False(t, updated)
ret, err = th.App.GetPluginKey(pluginId, "key")
ret, err = th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte("test"), ret)
// Test updating using correct old value
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", []byte("test"), []byte("test2"))
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", []byte("test"), []byte("test2"))
assert.Nil(t, err)
assert.True(t, updated)
ret, err = th.App.GetPluginKey(pluginId, "key")
ret, err = th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte("test2"), ret)
}
func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
pluginId := "testpluginid"
pluginID := "testpluginid"
t.Run("storing a value without providing options works", func(t *testing.T) {
th := Setup(t)
defer th.TearDown()
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-1"), model.PluginKVSetOptions{})
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-1"), model.PluginKVSetOptions{})
assert.True(t, result)
assert.Nil(t, err)
// and I can get it back!
ret, err := th.App.GetPluginKey(pluginId, "key")
ret, err := th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte(`value-1`), ret)
})
@@ -211,10 +211,10 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
th := Setup(t)
defer th.TearDown()
err := th.App.SetPluginKey(pluginId, "key", []byte("value-1"))
err := th.App.SetPluginKey(pluginID, "key", []byte("value-1"))
require.Nil(t, err)
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-3"), model.PluginKVSetOptions{
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-3"), model.PluginKVSetOptions{
Atomic: true,
OldValue: []byte("value-2"),
})
@@ -222,7 +222,7 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
assert.Nil(t, err)
// test that the value didn't change
ret, err := th.App.GetPluginKey(pluginId, "key")
ret, err := th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte(`value-1`), ret)
})
@@ -231,10 +231,10 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
th := Setup(t)
defer th.TearDown()
err := th.App.SetPluginKey(pluginId, "key", []byte("value-2"))
err := th.App.SetPluginKey(pluginID, "key", []byte("value-2"))
require.Nil(t, err)
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-3"), model.PluginKVSetOptions{
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-3"), model.PluginKVSetOptions{
Atomic: true,
OldValue: []byte("value-2"),
})
@@ -242,7 +242,7 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
assert.Nil(t, err)
// test that the value did change
ret, err := th.App.GetPluginKey(pluginId, "key")
ret, err := th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte(`value-3`), ret)
})
@@ -252,19 +252,19 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
defer th.TearDown()
// first set a value.
result, err := th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-2", []byte("value-1"), model.PluginKVSetOptions{})
result, err := th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-2", []byte("value-1"), model.PluginKVSetOptions{})
require.Nil(t, err)
require.True(t, result)
// now it should delete the set value.
result, err = th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-2", nil, model.PluginKVSetOptions{
result, err = th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-2", nil, model.PluginKVSetOptions{
Atomic: true,
OldValue: []byte("value-1"),
})
assert.Nil(t, err)
assert.True(t, result)
ret, err := th.App.GetPluginKey(pluginId, "nil-test-key-2")
ret, err := th.App.GetPluginKey(pluginID, "nil-test-key-2")
assert.Nil(t, err)
assert.Nil(t, ret)
})
@@ -274,22 +274,22 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
defer th.TearDown()
// first set a value.
result, err := th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-3", []byte("value-1"), model.PluginKVSetOptions{})
result, err := th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-3", []byte("value-1"), model.PluginKVSetOptions{})
require.Nil(t, err)
require.True(t, result)
// now it should delete the set value.
result, err = th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-3", nil, model.PluginKVSetOptions{})
result, err = th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-3", nil, model.PluginKVSetOptions{})
assert.Nil(t, err)
assert.True(t, result)
// verify a nil value is returned
ret, err := th.App.GetPluginKey(pluginId, "nil-test-key-3")
ret, err := th.App.GetPluginKey(pluginID, "nil-test-key-3")
assert.Nil(t, err)
assert.Nil(t, ret)
// verify the row is actually gone
list, err := th.App.ListPluginKeys(pluginId, 0, 1)
list, err := th.App.ListPluginKeys(pluginID, 0, 1)
assert.Nil(t, err)
assert.Empty(t, list)
})
@@ -298,14 +298,14 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
th := Setup(t)
defer th.TearDown()
result, err := th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-4", []byte("value-1"), model.PluginKVSetOptions{
result, err := th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-4", []byte("value-1"), model.PluginKVSetOptions{
Atomic: true,
OldValue: nil,
})
assert.Nil(t, err)
assert.True(t, result)
ret, err := th.App.GetPluginKey(pluginId, "nil-test-key-4")
ret, err := th.App.GetPluginKey(pluginID, "nil-test-key-4")
assert.Nil(t, err)
assert.Equal(t, []byte("value-1"), ret)
})
@@ -314,21 +314,21 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
th := Setup(t)
defer th.TearDown()
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-1"), model.PluginKVSetOptions{
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-1"), model.PluginKVSetOptions{
ExpireInSeconds: 1,
})
assert.True(t, result)
assert.Nil(t, err)
// test that the value is set
ret, err := th.App.GetPluginKey(pluginId, "key")
ret, err := th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Equal(t, []byte(`value-1`), ret)
// test that the value is not longer
time.Sleep(1500 * time.Millisecond)
ret, err = th.App.GetPluginKey(pluginId, "key")
ret, err = th.App.GetPluginKey(pluginID, "key")
assert.Nil(t, err)
assert.Nil(t, ret)
})