This commit is contained in:
1 parent
72bc974aa6
commit
9ec2585030
12 files changed
+299
-54
No files matched your search
@@ -98,7 +98,7 @@ func (m *MockFS) ReadDir(path string) ([]os.FileInfo, error) {
|
||||
if len(prefix) > 0 && prefix[len(prefix)-1] != '/' {
|
||||
prefix += "/"
|
||||
}
|
||||
|
||||
|
||||
if len(p) > len(prefix) && p[:len(prefix)] == prefix {
|
||||
// Ensure direct child (no more slashes)
|
||||
rel := p[len(prefix):]
|
||||
@@ -150,7 +150,7 @@ func TestCachedClient_Stat(t *testing.T) {
|
||||
mockFS := NewMockFS()
|
||||
mockFS.AddFile("/test.txt", []byte("hello"))
|
||||
|
||||
c := NewCachedClient(mockFS, client, time.Hour)
|
||||
c := NewCachedClient(mockFS, client, time.Hour, time.Hour*2)
|
||||
|
||||
// First call: Cache miss
|
||||
info, err := c.Stat("/test.txt")
|
||||
@@ -209,7 +209,7 @@ func TestCachedClient_Read(t *testing.T) {
|
||||
content := []byte("hello world")
|
||||
mockFS.AddFile("/read.txt", content)
|
||||
|
||||
c := NewCachedClient(mockFS, client, time.Hour)
|
||||
c := NewCachedClient(mockFS, client, time.Hour, time.Hour*2)
|
||||
|
||||
// First call: Miss
|
||||
data, err := c.Read("/read.txt")
|
||||
@@ -257,7 +257,7 @@ func TestCachedClient_ReadDir(t *testing.T) {
|
||||
mockFS.AddFile("/dir/f1.txt", []byte("1"))
|
||||
mockFS.AddFile("/dir/f2.txt", []byte("2"))
|
||||
|
||||
c := NewCachedClient(mockFS, client, time.Hour)
|
||||
c := NewCachedClient(mockFS, client, time.Hour, time.Hour*2)
|
||||
|
||||
// First call: Miss
|
||||
infos, err := c.ReadDir("/dir")
|
||||
@@ -303,7 +303,7 @@ func TestCachedClient_RevalidateStat(t *testing.T) {
|
||||
mockFS := NewMockFS()
|
||||
mockFS.AddFile("/reval.txt", []byte("initial"))
|
||||
|
||||
c := NewCachedClient(mockFS, client, time.Hour)
|
||||
c := NewCachedClient(mockFS, client, time.Hour, time.Hour*2)
|
||||
|
||||
// Populate cache
|
||||
_, _ = c.Stat("/reval.txt")
|
||||
@@ -342,7 +342,7 @@ func TestCachedClient_RevalidateStat(t *testing.T) {
|
||||
// We can inspect redis directly or trust `Stat` returns cached value (which should be updated).
|
||||
// Let's inspect redis to be sure.
|
||||
// Or just call Stat again. It should be a cache HIT, but return NEW values.
|
||||
|
||||
|
||||
// Reset stats to check hit
|
||||
c.hits.Store(0)
|
||||
c.misses.Store(0)
|
||||
@@ -351,11 +351,11 @@ func TestCachedClient_RevalidateStat(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Stat failed: %v", err)
|
||||
}
|
||||
|
||||
|
||||
if info.Size() != int64(len("updated content")) {
|
||||
t.Errorf("expected size %d, got %d", len("updated content"), info.Size())
|
||||
}
|
||||
|
||||
|
||||
// Should be a hit because revalidate updated the cache entry, so it exists and is valid.
|
||||
if c.hits.Load() != 1 {
|
||||
t.Errorf("expected 1 hit, got %d", c.hits.Load())
|
||||
@@ -381,7 +381,7 @@ func TestCachedClient_RevalidateRead(t *testing.T) {
|
||||
mockFS := NewMockFS()
|
||||
mockFS.AddFile("/read_reval.txt", []byte("initial"))
|
||||
|
||||
c := NewCachedClient(mockFS, client, time.Hour)
|
||||
c := NewCachedClient(mockFS, client, time.Hour, time.Hour*2)
|
||||
|
||||
// Populate cache
|
||||
_, _ = c.Read("/read_reval.txt")
|
||||
@@ -431,7 +431,7 @@ func TestCachedClient_RevalidateReadDir(t *testing.T) {
|
||||
mockFS.AddDir("/dir_reval")
|
||||
mockFS.AddFile("/dir_reval/f1.txt", []byte("1"))
|
||||
|
||||
c := NewCachedClient(mockFS, client, time.Hour)
|
||||
c := NewCachedClient(mockFS, client, time.Hour, time.Hour*2)
|
||||
|
||||
// Populate cache
|
||||
_, err = c.ReadDir("/dir_reval")
|
||||
@@ -461,4 +461,3 @@ func TestCachedClient_RevalidateReadDir(t *testing.T) {
|
||||
t.Errorf("expected 1 hit, got %d", c.hits.Load())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user