2024-02-12 04:52:41 +08:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-08-31 23:50:17 +08:00
|
|
|
"github.com/tgdrive/teldrive/pkg/schemas"
|
2024-02-12 04:52:41 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
|
|
|
|
|
|
|
var value = schemas.FileIn{
|
|
|
|
Name: "file.jpeg",
|
|
|
|
Type: "file",
|
|
|
|
}
|
|
|
|
var result schemas.FileIn
|
|
|
|
|
2024-07-26 23:50:26 +08:00
|
|
|
cache := NewMemoryCache(1 * 1024 * 1024)
|
|
|
|
|
|
|
|
err := cache.Set("key", value, 1*time.Second)
|
2024-02-12 04:52:41 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = cache.Get("key", &result)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, result, value)
|
|
|
|
}
|