Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/codeGROOVE-dev/fido

go 1.25.4

require github.com/puzpuzpuz/xsync/v4 v4.2.0
require github.com/puzpuzpuz/xsync/v4 v4.3.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/puzpuzpuz/xsync/v4 v4.2.0 h1:dlxm77dZj2c3rxq0/XNvvUKISAmovoXF4a4qM6Wvkr0=
github.com/puzpuzpuz/xsync/v4 v4.2.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
github.com/puzpuzpuz/xsync/v4 v4.3.0 h1:w/bWkEJdYuRNYhHn5eXnIT8LzDM1O629X1I9MJSkD7Q=
github.com/puzpuzpuz/xsync/v4 v4.3.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo=
4 changes: 2 additions & 2 deletions pkg/store/cloudrun/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
)

require (
github.com/codeGROOVE-dev/ds9 v0.8.0 // indirect
github.com/klauspost/compress v1.18.2 // indirect
github.com/codeGROOVE-dev/ds9 v0.8.1 // indirect
github.com/klauspost/compress v1.18.3 // indirect
)

replace github.com/codeGROOVE-dev/fido/pkg/store/datastore => ../datastore
Expand Down
8 changes: 4 additions & 4 deletions pkg/store/cloudrun/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/codeGROOVE-dev/ds9 v0.8.0 h1:A23VvL1YzUBZyXNYmF5u0R6nPcxQitPeLo8FFk6OiUs=
github.com/codeGROOVE-dev/ds9 v0.8.0/go.mod h1:0UDipxF1DADfqM5GtjefgB2u+EXdDgOKmxVvrSGLHoM=
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/codeGROOVE-dev/ds9 v0.8.1 h1:jXSCoKe6iSjhgdbN1XFkMd1reE0yFWI4fpH5QHtrE4Y=
github.com/codeGROOVE-dev/ds9 v0.8.1/go.mod h1:0UDipxF1DADfqM5GtjefgB2u+EXdDgOKmxVvrSGLHoM=
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
2 changes: 1 addition & 1 deletion pkg/store/compress/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/codeGROOVE-dev/fido/pkg/store/compress

go 1.25.4

require github.com/klauspost/compress v1.18.2
require github.com/klauspost/compress v1.18.3
4 changes: 2 additions & 2 deletions pkg/store/compress/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
4 changes: 2 additions & 2 deletions pkg/store/datastore/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/codeGROOVE-dev/fido/pkg/store/datastore
go 1.25.4

require (
github.com/codeGROOVE-dev/ds9 v0.8.0
github.com/codeGROOVE-dev/ds9 v0.8.1
github.com/codeGROOVE-dev/fido/pkg/store/compress v1.10.0
)

require github.com/klauspost/compress v1.18.2 // indirect
require github.com/klauspost/compress v1.18.3 // indirect

replace github.com/codeGROOVE-dev/fido/pkg/store/compress => ../compress
8 changes: 4 additions & 4 deletions pkg/store/datastore/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/codeGROOVE-dev/ds9 v0.8.0 h1:A23VvL1YzUBZyXNYmF5u0R6nPcxQitPeLo8FFk6OiUs=
github.com/codeGROOVE-dev/ds9 v0.8.0/go.mod h1:0UDipxF1DADfqM5GtjefgB2u+EXdDgOKmxVvrSGLHoM=
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/codeGROOVE-dev/ds9 v0.8.1 h1:jXSCoKe6iSjhgdbN1XFkMd1reE0yFWI4fpH5QHtrE4Y=
github.com/codeGROOVE-dev/ds9 v0.8.1/go.mod h1:0UDipxF1DADfqM5GtjefgB2u+EXdDgOKmxVvrSGLHoM=
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
184 changes: 184 additions & 0 deletions pkg/store/datastore/persist_datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datastore

import (
"context"
"maps"
"os"
"testing"
"time"
Expand Down Expand Up @@ -328,3 +329,186 @@ func TestDatastorePersist_CleanupEmpty(t *testing.T) {
t.Logf("Cleanup count = %d (found existing expired entries)", count)
}
}

func TestDatastorePersist_Keys(t *testing.T) {
ctx := context.Background()
dp, cleanup := createTestStore[string, string](t, ctx)
defer cleanup()

// Set entries with different prefixes
entries := map[string]string{
"user:alice": "alice-data",
"user:bob": "bob-data",
"user:charlie": "charlie-data",
"post:1": "post-1-data",
"post:2": "post-2-data",
"other": "other-data",
}

for k, v := range entries {
if err := dp.Set(ctx, k, v, time.Time{}); err != nil {
t.Fatalf("Set %s: %v", k, err)
}
}

tests := []struct {
name string
prefix string
want []string
}{
{"user prefix", "user:", []string{"user:alice", "user:bob", "user:charlie"}},
{"post prefix", "post:", []string{"post:1", "post:2"}},
{"other prefix", "other", []string{"other"}},
{"no match", "nomatch:", []string{}},
{"empty prefix", "", []string{"other", "post:1", "post:2", "user:alice", "user:bob", "user:charlie"}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var keys []string
for k := range dp.Keys(ctx, tt.prefix) {
keys = append(keys, k)
}

if len(keys) != len(tt.want) {
t.Errorf("Keys() returned %d keys; want %d. Got: %v, Want: %v", len(keys), len(tt.want), keys, tt.want)
return
}

// Create map for comparison
keyMap := make(map[string]bool)
for _, k := range keys {
keyMap[k] = true
}

for _, wantKey := range tt.want {
if !keyMap[wantKey] {
t.Errorf("Keys() missing key %q", wantKey)
}
}
})
}

// Cleanup all test entries
for k := range entries {
if err := dp.Delete(ctx, k); err != nil {
t.Logf("Delete error: %v", err)
}
}
}

func TestDatastorePersist_Range(t *testing.T) {
ctx := context.Background()
dp, cleanup := createTestStore[string, string](t, ctx)
defer cleanup()

// Set entries with different prefixes
entries := map[string]string{
"user:alice": "alice-data",
"user:bob": "bob-data",
"user:charlie": "charlie-data",
"post:1": "post-1-data",
"post:2": "post-2-data",
"other": "other-data",
}

for k, v := range entries {
if err := dp.Set(ctx, k, v, time.Time{}); err != nil {
t.Fatalf("Set %s: %v", k, err)
}
}

tests := []struct {
name string
prefix string
want map[string]string
}{
{"user prefix", "user:", map[string]string{
"user:alice": "alice-data",
"user:bob": "bob-data",
"user:charlie": "charlie-data",
}},
{"post prefix", "post:", map[string]string{
"post:1": "post-1-data",
"post:2": "post-2-data",
}},
{"other prefix", "other", map[string]string{
"other": "other-data",
}},
{"no match", "nomatch:", map[string]string{}},
{"empty prefix", "", entries},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := maps.Collect(dp.Range(ctx, tt.prefix))

if len(result) != len(tt.want) {
t.Errorf("Range() returned %d entries; want %d", len(result), len(tt.want))
return
}

for k, wantVal := range tt.want {
gotVal, found := result[k]
if !found {
t.Errorf("Range() missing key %q", k)
continue
}
if gotVal != wantVal {
t.Errorf("Range() key %q = %q; want %q", k, gotVal, wantVal)
}
}
})
}

// Cleanup all test entries
for k := range entries {
if err := dp.Delete(ctx, k); err != nil {
t.Logf("Delete error: %v", err)
}
}
}

func TestDatastorePersist_Range_SkipsExpired(t *testing.T) {
ctx := context.Background()
dp, cleanup := createTestStore[string, string](t, ctx)
defer cleanup()

// Set entries with different expiry times
past := time.Now().Add(-1 * time.Hour)
future := time.Now().Add(1 * time.Hour)

if err := dp.Set(ctx, "expired-1", "value1", past); err != nil {
t.Fatalf("Set: %v", err)
}
if err := dp.Set(ctx, "valid-1", "value2", future); err != nil {
t.Fatalf("Set: %v", err)
}
if err := dp.Set(ctx, "valid-2", "value3", time.Time{}); err != nil {
t.Fatalf("Set: %v", err)
}

// Range should only return valid entries
result := maps.Collect(dp.Range(ctx, ""))

if len(result) != 2 {
t.Errorf("Range() returned %d entries; want 2 (expired entries should be skipped)", len(result))
}

if _, found := result["expired-1"]; found {
t.Error("Range() should skip expired entries")
}

if val, found := result["valid-1"]; !found || val != "value2" {
t.Error("Range() should return valid-1")
}

if val, found := result["valid-2"]; !found || val != "value3" {
t.Error("Range() should return valid-2")
}

// Cleanup
_ = dp.Delete(ctx, "valid-1") //nolint:errcheck // test cleanup
_ = dp.Delete(ctx, "valid-2") //nolint:errcheck // test cleanup
_ = dp.Delete(ctx, "expired-1") //nolint:errcheck // test cleanup
}
2 changes: 1 addition & 1 deletion pkg/store/localfs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.25.4

require (
github.com/codeGROOVE-dev/fido/pkg/store/compress v1.10.0
github.com/klauspost/compress v1.18.2
github.com/klauspost/compress v1.18.3
github.com/pierrec/lz4/v4 v4.1.22
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/store/localfs/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
Loading
Loading