|
|
|
|
@ -111,9 +111,9 @@ func TestScope_ScopedStore_Good_SetGet(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("config", "theme", "dark"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("config", "theme", "dark"))
|
|
|
|
|
|
|
|
|
|
value, err := scopedStore.Get("config", "theme")
|
|
|
|
|
value, err := scopedStore.GetFrom("config", "theme")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "dark", value)
|
|
|
|
|
}
|
|
|
|
|
@ -151,8 +151,8 @@ func TestScope_ScopedStore_Good_AllSeq(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "first", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "second", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "first", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "second", "2"))
|
|
|
|
|
|
|
|
|
|
var keys []string
|
|
|
|
|
for entry, err := range scopedStore.AllSeq("items") {
|
|
|
|
|
@ -168,7 +168,7 @@ func TestScope_ScopedStore_Good_PrefixedInUnderlyingStore(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("config", "key", "val"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("config", "key", "val"))
|
|
|
|
|
|
|
|
|
|
value, err := storeInstance.Get("tenant-a:config", "key")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@ -185,14 +185,14 @@ func TestScope_ScopedStore_Good_NamespaceIsolation(t *testing.T) {
|
|
|
|
|
alphaStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
betaStore := mustScoped(t, storeInstance, "tenant-b")
|
|
|
|
|
|
|
|
|
|
require.NoError(t, alphaStore.Set("config", "colour", "blue"))
|
|
|
|
|
require.NoError(t, betaStore.Set("config", "colour", "red"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("config", "colour", "blue"))
|
|
|
|
|
require.NoError(t, betaStore.SetIn("config", "colour", "red"))
|
|
|
|
|
|
|
|
|
|
alphaValue, err := alphaStore.Get("config", "colour")
|
|
|
|
|
alphaValue, err := alphaStore.GetFrom("config", "colour")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "blue", alphaValue)
|
|
|
|
|
|
|
|
|
|
betaValue, err := betaStore.Get("config", "colour")
|
|
|
|
|
betaValue, err := betaStore.GetFrom("config", "colour")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "red", betaValue)
|
|
|
|
|
}
|
|
|
|
|
@ -202,10 +202,10 @@ func TestScope_ScopedStore_Good_Delete(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.Delete("g", "k"))
|
|
|
|
|
|
|
|
|
|
_, err := scopedStore.Get("g", "k")
|
|
|
|
|
_, err := scopedStore.GetFrom("g", "k")
|
|
|
|
|
assert.True(t, core.Is(err, NotFoundError))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -214,8 +214,8 @@ func TestScope_ScopedStore_Good_DeleteGroup(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.DeleteGroup("g"))
|
|
|
|
|
|
|
|
|
|
count, err := scopedStore.Count("g")
|
|
|
|
|
@ -230,9 +230,9 @@ func TestScope_ScopedStore_Good_GetAll(t *testing.T) {
|
|
|
|
|
alphaStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
betaStore := mustScoped(t, storeInstance, "tenant-b")
|
|
|
|
|
|
|
|
|
|
require.NoError(t, alphaStore.Set("items", "x", "1"))
|
|
|
|
|
require.NoError(t, alphaStore.Set("items", "y", "2"))
|
|
|
|
|
require.NoError(t, betaStore.Set("items", "z", "3"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("items", "x", "1"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("items", "y", "2"))
|
|
|
|
|
require.NoError(t, betaStore.SetIn("items", "z", "3"))
|
|
|
|
|
|
|
|
|
|
all, err := alphaStore.GetAll("items")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@ -248,8 +248,8 @@ func TestScope_ScopedStore_Good_All(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "first", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "second", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "first", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "second", "2"))
|
|
|
|
|
|
|
|
|
|
var keys []string
|
|
|
|
|
for entry, err := range scopedStore.All("items") {
|
|
|
|
|
@ -265,9 +265,9 @@ func TestScope_ScopedStore_Good_All_SortedByKey(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "charlie", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "alpha", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("items", "bravo", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "charlie", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "alpha", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("items", "bravo", "2"))
|
|
|
|
|
|
|
|
|
|
var keys []string
|
|
|
|
|
for entry, err := range scopedStore.All("items") {
|
|
|
|
|
@ -283,8 +283,8 @@ func TestScope_ScopedStore_Good_Count(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "b", "2"))
|
|
|
|
|
|
|
|
|
|
count, err := scopedStore.Count("g")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@ -298,7 +298,7 @@ func TestScope_ScopedStore_Good_SetWithTTL(t *testing.T) {
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.SetWithTTL("g", "k", "v", time.Hour))
|
|
|
|
|
|
|
|
|
|
value, err := scopedStore.Get("g", "k")
|
|
|
|
|
value, err := scopedStore.GetFrom("g", "k")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "v", value)
|
|
|
|
|
}
|
|
|
|
|
@ -311,7 +311,7 @@ func TestScope_ScopedStore_Good_SetWithTTL_Expires(t *testing.T) {
|
|
|
|
|
require.NoError(t, scopedStore.SetWithTTL("g", "k", "v", 1*time.Millisecond))
|
|
|
|
|
time.Sleep(5 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
_, err := scopedStore.Get("g", "k")
|
|
|
|
|
_, err := scopedStore.GetFrom("g", "k")
|
|
|
|
|
assert.True(t, core.Is(err, NotFoundError))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -320,7 +320,7 @@ func TestScope_ScopedStore_Good_Render(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("user", "name", "Alice"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("user", "name", "Alice"))
|
|
|
|
|
|
|
|
|
|
renderedTemplate, err := scopedStore.Render("Hello {{ .name }}", "user")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@ -334,9 +334,9 @@ func TestScope_ScopedStore_Good_BulkHelpers(t *testing.T) {
|
|
|
|
|
alphaStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
betaStore := mustScoped(t, storeInstance, "tenant-b")
|
|
|
|
|
|
|
|
|
|
require.NoError(t, alphaStore.Set("config", "colour", "blue"))
|
|
|
|
|
require.NoError(t, alphaStore.Set("sessions", "token", "abc123"))
|
|
|
|
|
require.NoError(t, betaStore.Set("config", "colour", "red"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("config", "colour", "blue"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("sessions", "token", "abc123"))
|
|
|
|
|
require.NoError(t, betaStore.SetIn("config", "colour", "red"))
|
|
|
|
|
|
|
|
|
|
count, err := alphaStore.CountAll("")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@ -374,8 +374,8 @@ func TestScope_ScopedStore_Good_GroupsSeqStopsEarly(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("alpha", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("beta", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("alpha", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("beta", "b", "2"))
|
|
|
|
|
|
|
|
|
|
groups := scopedStore.GroupsSeq("")
|
|
|
|
|
var seen []string
|
|
|
|
|
@ -393,9 +393,9 @@ func TestScope_ScopedStore_Good_GroupsSeqSorted(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("charlie", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("alpha", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("bravo", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("charlie", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("alpha", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("bravo", "b", "2"))
|
|
|
|
|
|
|
|
|
|
var groupNames []string
|
|
|
|
|
for groupName, iterationErr := range scopedStore.GroupsSeq("") {
|
|
|
|
|
@ -411,8 +411,8 @@ func TestScope_ScopedStore_Good_GetSplitAndGetFields(t *testing.T) {
|
|
|
|
|
defer storeInstance.Close()
|
|
|
|
|
|
|
|
|
|
scopedStore := mustScoped(t, storeInstance, "tenant-a")
|
|
|
|
|
require.NoError(t, scopedStore.Set("config", "hosts", "alpha,beta,gamma"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("config", "flags", "one two\tthree\n"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("config", "hosts", "alpha,beta,gamma"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("config", "flags", "one two\tthree\n"))
|
|
|
|
|
|
|
|
|
|
parts, err := scopedStore.GetSplit("config", "hosts", ",")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@ -445,7 +445,7 @@ func TestScope_ScopedStore_Good_PurgeExpired(t *testing.T) {
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, int64(1), removedRows)
|
|
|
|
|
|
|
|
|
|
_, err = scopedStore.Get("session", "token")
|
|
|
|
|
_, err = scopedStore.GetFrom("session", "token")
|
|
|
|
|
assert.True(t, core.Is(err, NotFoundError))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -483,10 +483,10 @@ func TestScope_Quota_Good_MaxKeys(t *testing.T) {
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
for i := range 5 {
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", keyName(i), "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", keyName(i), "v"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = scopedStore.Set("g", "overflow", "v")
|
|
|
|
|
err = scopedStore.SetIn("g", "overflow", "v")
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
}
|
|
|
|
|
@ -503,7 +503,7 @@ func TestScope_Quota_Bad_QuotaCheckQueryError(t *testing.T) {
|
|
|
|
|
scopedStore, err := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 1})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
err = scopedStore.Set("config", "theme", "dark")
|
|
|
|
|
err = scopedStore.SetIn("config", "theme", "dark")
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "quota check")
|
|
|
|
|
}
|
|
|
|
|
@ -514,11 +514,11 @@ func TestScope_Quota_Good_MaxKeys_AcrossGroups(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 3})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g3", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g3", "c", "3"))
|
|
|
|
|
|
|
|
|
|
err := scopedStore.Set("g4", "d", "4")
|
|
|
|
|
err := scopedStore.SetIn("g4", "d", "4")
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -528,12 +528,12 @@ func TestScope_Quota_Good_UpsertDoesNotCount(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 3})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "a", "updated"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "a", "updated"))
|
|
|
|
|
|
|
|
|
|
value, err := scopedStore.Get("g", "a")
|
|
|
|
|
value, err := scopedStore.GetFrom("g", "a")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "updated", value)
|
|
|
|
|
}
|
|
|
|
|
@ -544,11 +544,11 @@ func TestScope_Quota_Good_DeleteAndReInsert(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 3})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.Delete("g", "c"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "d", "4"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "d", "4"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestScope_Quota_Good_ZeroMeansUnlimited(t *testing.T) {
|
|
|
|
|
@ -558,7 +558,7 @@ func TestScope_Quota_Good_ZeroMeansUnlimited(t *testing.T) {
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 0, MaxGroups: 0})
|
|
|
|
|
|
|
|
|
|
for i := range 100 {
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", keyName(i), "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", keyName(i), "v"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -570,14 +570,14 @@ func TestScope_Quota_Good_ExpiredKeysExcluded(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.SetWithTTL("g", "temp1", "v", 1*time.Millisecond))
|
|
|
|
|
require.NoError(t, scopedStore.SetWithTTL("g", "temp2", "v", 1*time.Millisecond))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "permanent", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "permanent", "v"))
|
|
|
|
|
|
|
|
|
|
time.Sleep(5 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "new1", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g", "new2", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "new1", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g", "new2", "v"))
|
|
|
|
|
|
|
|
|
|
err := scopedStore.Set("g", "new3", "v")
|
|
|
|
|
err := scopedStore.SetIn("g", "new3", "v")
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -604,11 +604,11 @@ func TestScope_Quota_Good_MaxGroups(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxGroups: 3})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g3", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g3", "k", "v"))
|
|
|
|
|
|
|
|
|
|
err := scopedStore.Set("g4", "k", "v")
|
|
|
|
|
err := scopedStore.SetIn("g4", "k", "v")
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
}
|
|
|
|
|
@ -619,10 +619,10 @@ func TestScope_Quota_Good_MaxGroups_ExistingGroupOK(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxGroups: 2})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "d", "4"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "c", "3"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "d", "4"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestScope_Quota_Good_MaxGroups_DeleteAndRecreate(t *testing.T) {
|
|
|
|
|
@ -631,10 +631,10 @@ func TestScope_Quota_Good_MaxGroups_DeleteAndRecreate(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxGroups: 2})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.DeleteGroup("g1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g3", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g3", "k", "v"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestScope_Quota_Good_MaxGroups_ZeroUnlimited(t *testing.T) {
|
|
|
|
|
@ -644,7 +644,7 @@ func TestScope_Quota_Good_MaxGroups_ZeroUnlimited(t *testing.T) {
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxGroups: 0})
|
|
|
|
|
|
|
|
|
|
for i := range 50 {
|
|
|
|
|
require.NoError(t, scopedStore.Set(keyName(i), "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn(keyName(i), "k", "v"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -655,11 +655,11 @@ func TestScope_Quota_Good_MaxGroups_ExpiredGroupExcluded(t *testing.T) {
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxGroups: 2})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.SetWithTTL("g1", "k", "v", 1*time.Millisecond))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "k", "v"))
|
|
|
|
|
|
|
|
|
|
time.Sleep(5 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g3", "k", "v"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g3", "k", "v"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestScope_Quota_Good_BothLimits(t *testing.T) {
|
|
|
|
|
@ -668,13 +668,13 @@ func TestScope_Quota_Good_BothLimits(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
scopedStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 10, MaxGroups: 2})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.Set("g2", "b", "2"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "a", "1"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g2", "b", "2"))
|
|
|
|
|
|
|
|
|
|
err := scopedStore.Set("g3", "c", "3")
|
|
|
|
|
err := scopedStore.SetIn("g3", "c", "3")
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
|
|
|
|
|
require.NoError(t, scopedStore.Set("g1", "d", "4"))
|
|
|
|
|
require.NoError(t, scopedStore.SetIn("g1", "d", "4"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestScope_Quota_Good_DoesNotAffectOtherNamespaces(t *testing.T) {
|
|
|
|
|
@ -684,15 +684,15 @@ func TestScope_Quota_Good_DoesNotAffectOtherNamespaces(t *testing.T) {
|
|
|
|
|
alphaStore, _ := NewScopedWithQuota(storeInstance, "tenant-a", QuotaConfig{MaxKeys: 2})
|
|
|
|
|
betaStore, _ := NewScopedWithQuota(storeInstance, "tenant-b", QuotaConfig{MaxKeys: 2})
|
|
|
|
|
|
|
|
|
|
require.NoError(t, alphaStore.Set("g", "a1", "v"))
|
|
|
|
|
require.NoError(t, alphaStore.Set("g", "a2", "v"))
|
|
|
|
|
require.NoError(t, betaStore.Set("g", "b1", "v"))
|
|
|
|
|
require.NoError(t, betaStore.Set("g", "b2", "v"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("g", "a1", "v"))
|
|
|
|
|
require.NoError(t, alphaStore.SetIn("g", "a2", "v"))
|
|
|
|
|
require.NoError(t, betaStore.SetIn("g", "b1", "v"))
|
|
|
|
|
require.NoError(t, betaStore.SetIn("g", "b2", "v"))
|
|
|
|
|
|
|
|
|
|
err := alphaStore.Set("g", "a3", "v")
|
|
|
|
|
err := alphaStore.SetIn("g", "a3", "v")
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
|
|
|
|
|
err = betaStore.Set("g", "b3", "v")
|
|
|
|
|
err = betaStore.SetIn("g", "b3", "v")
|
|
|
|
|
assert.True(t, core.Is(err, QuotaExceededError))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|