Skip to content

Commit 6468dae

Browse files
refactor: remove RAWCache and expand NewCacheFromURL tests
1 parent 4ccd142 commit 6468dae

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

cache/common.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ type Cache interface {
2222
Delete(ctx context.Context, key string) error
2323
}
2424

25-
type RAWCache interface {
26-
Raw() Cache
27-
}
28-
2925
type CloserCache interface {
3026
Cache
3127
io.Closer
@@ -36,10 +32,6 @@ type closerCache struct {
3632
closer func() error
3733
}
3834

39-
func (c closerCache) Raw() Cache {
40-
return c.Cache
41-
}
42-
4335
func (c closerCache) Close() error {
4436
return c.closer()
4537
}

cache/common_test.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,44 @@ func testCacheErrorReader(t *testing.T, factory CacheFactory) {
202202

203203
func TestCommonFunctions(t *testing.T) {
204204
t.Run("NewCacheFromURL", func(t *testing.T) {
205-
c, err := NewCacheFromURL("memory://?max_capacity=10")
205+
// 1. Memory with parameters
206+
c1, err := NewCacheFromURL("memory://?max_capacity=100&cleanup_interval=1m")
206207
assert.NoError(t, err)
207-
c.Close()
208+
assert.NotNil(t, c1)
209+
_ = c1.Close()
208210

209-
_, err = NewCacheFromURL("invalid://")
210-
assert.Error(t, err)
211+
// 2. Memory with defaults
212+
c2, err := NewCacheFromURL("mem://")
213+
assert.NoError(t, err)
214+
assert.NotNil(t, c2)
215+
_ = c2.Close()
216+
217+
// 3. Redis (basic parsing)
218+
c3, err := NewCacheFromURL("redis://localhost:6379/0?prefix=test:")
219+
if err == nil {
220+
assert.NotNil(t, c3)
221+
_ = c3.Close()
222+
}
223+
224+
// 4. Error cases
225+
testCases := []struct {
226+
name string
227+
url string
228+
}{
229+
{"InvalidURL", ":%"},
230+
{"UnsupportedScheme", "unknown://"},
231+
{"InvalidCapacity", "memory://?max_capacity=-1"},
232+
{"ZeroCapacity", "memory://?max_capacity=0"},
233+
{"NonIntCapacity", "memory://?max_capacity=abc"},
234+
{"InvalidInterval", "memory://?cleanup_interval=invalid"},
235+
}
236+
237+
for _, tc := range testCases {
238+
t.Run(tc.name, func(t *testing.T) {
239+
_, err := NewCacheFromURL(tc.url)
240+
assert.Error(t, err)
241+
})
242+
}
211243
})
212244

213245
t.Run("ReadToString", func(t *testing.T) {

0 commit comments

Comments
 (0)