Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/store/RFC.md fully. Find features d...' (#44) from agent/read---spec-code-core-go-store-rfc-md-fu into dev
This commit is contained in:
commit
89c6a642ef
8 changed files with 94 additions and 118 deletions
|
|
@ -85,7 +85,7 @@ func main() {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := scopedStore.Set("config", "theme", "dark"); err != nil {
|
||||
if err := scopedStore.SetIn("config", "theme", "dark"); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ func main() {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := quotaScopedStore.Set("prefs", "locale", "en-GB"); err != nil {
|
||||
if err := quotaScopedStore.SetIn("prefs", "locale", "en-GB"); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func main() {
|
|||
if scopedStore == nil {
|
||||
return
|
||||
}
|
||||
if err := scopedStore.Set("preferences", "locale", "en-GB"); err != nil {
|
||||
if err := scopedStore.SetIn("preferences", "locale", "en-GB"); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
doc.go
2
doc.go
|
|
@ -52,7 +52,7 @@
|
|||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// if err := scopedStore.Set("preferences", "locale", "en-GB"); err != nil {
|
||||
// if err := scopedStore.SetIn("preferences", "locale", "en-GB"); err != nil {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ scopedStore, err := store.NewScoped(storeInstance, "tenant-42")
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := scopedStore.Set("config", "colour", "blue"); err != nil {
|
||||
if err := scopedStore.SetIn("config", "colour", "blue"); err != nil {
|
||||
return
|
||||
}
|
||||
// Stored in underlying store as group="tenant-42:config", key="colour"
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func main() {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err := scopedStore.Set("preferences", "locale", "en-GB"); err != nil {
|
||||
if err := scopedStore.SetIn("preferences", "locale", "en-GB"); err != nil {
|
||||
return
|
||||
}
|
||||
// Stored internally as group "tenant-42:preferences", key "locale"
|
||||
|
|
@ -84,7 +84,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
// A write past the limit returns store.QuotaExceededError.
|
||||
if err := quotaScopedStore.Set("g", "k", "v"); err != nil {
|
||||
if err := quotaScopedStore.SetIn("g", "k", "v"); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ func TestEvents_Watch_Good_ScopedStoreEventGroup(t *testing.T) {
|
|||
events := storeInstance.Watch("tenant-a:config")
|
||||
defer storeInstance.Unwatch("tenant-a:config", events)
|
||||
|
||||
require.NoError(t, scopedStore.Set("config", "theme", "dark"))
|
||||
require.NoError(t, scopedStore.SetIn("config", "theme", "dark"))
|
||||
|
||||
select {
|
||||
case event := <-events:
|
||||
|
|
|
|||
32
scope.go
32
scope.go
|
|
@ -85,20 +85,8 @@ func (scopedStore *ScopedStore) Namespace() string {
|
|||
}
|
||||
|
||||
// Usage example: `colourValue, err := scopedStore.Get("colour")`
|
||||
// Usage example: `colourValue, err := scopedStore.Get("config", "colour")`
|
||||
func (scopedStore *ScopedStore) Get(arguments ...string) (string, error) {
|
||||
switch len(arguments) {
|
||||
case 1:
|
||||
return scopedStore.GetFrom(defaultScopedGroupName, arguments[0])
|
||||
case 2:
|
||||
return scopedStore.GetFrom(arguments[0], arguments[1])
|
||||
default:
|
||||
return "", core.E(
|
||||
"store.ScopedStore.Get",
|
||||
core.Sprintf("expected 1 or 2 arguments; got %d", len(arguments)),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
func (scopedStore *ScopedStore) Get(key string) (string, error) {
|
||||
return scopedStore.GetFrom(defaultScopedGroupName, key)
|
||||
}
|
||||
|
||||
// Usage example: `colourValue, err := scopedStore.GetFrom("config", "colour")`
|
||||
|
|
@ -107,20 +95,8 @@ func (scopedStore *ScopedStore) GetFrom(group, key string) (string, error) {
|
|||
}
|
||||
|
||||
// Usage example: `if err := scopedStore.Set("colour", "blue"); err != nil { return }`
|
||||
// Usage example: `if err := scopedStore.Set("config", "colour", "blue"); err != nil { return }`
|
||||
func (scopedStore *ScopedStore) Set(arguments ...string) error {
|
||||
switch len(arguments) {
|
||||
case 2:
|
||||
return scopedStore.SetIn(defaultScopedGroupName, arguments[0], arguments[1])
|
||||
case 3:
|
||||
return scopedStore.SetIn(arguments[0], arguments[1], arguments[2])
|
||||
default:
|
||||
return core.E(
|
||||
"store.ScopedStore.Set",
|
||||
core.Sprintf("expected 2 or 3 arguments; got %d", len(arguments)),
|
||||
nil,
|
||||
)
|
||||
}
|
||||
func (scopedStore *ScopedStore) Set(key, value string) error {
|
||||
return scopedStore.SetIn(defaultScopedGroupName, key, value)
|
||||
}
|
||||
|
||||
// Usage example: `if err := scopedStore.SetIn("config", "colour", "blue"); err != nil { return }`
|
||||
|
|
|
|||
164
scope_test.go
164
scope_test.go
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue