All checks were successful
Release Tag / release (push) Successful in 13s
feat: add upstream support allowing to chain cache servers if needed fix: tweaked garbage collection to be better
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package steamcache
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCaching(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
td := t.TempDir()
|
|
|
|
os.WriteFile(filepath.Join(td, "key2"), []byte("value2"), 0644)
|
|
|
|
sc := New("localhost:8080", "1GB", 10, "1GB", 100, td, "", false)
|
|
|
|
sc.dirty = true
|
|
sc.LogStats()
|
|
|
|
if err := sc.vfs.Set("key", []byte("value")); err != nil {
|
|
t.Errorf("Set failed: %v", err)
|
|
}
|
|
if err := sc.vfs.Set("key1", []byte("value1")); err != nil {
|
|
t.Errorf("Set failed: %v", err)
|
|
}
|
|
|
|
sc.dirty = true
|
|
sc.LogStats()
|
|
|
|
if sc.diskgc.Size() != 17 {
|
|
t.Errorf("Size failed: got %d, want %d", sc.diskgc.Size(), 17)
|
|
}
|
|
|
|
if sc.vfs.Size() != 17 {
|
|
t.Errorf("Size failed: got %d, want %d", sc.vfs.Size(), 17)
|
|
}
|
|
|
|
if d, err := sc.vfs.Get("key"); err != nil {
|
|
t.Errorf("Get failed: %v", err)
|
|
} else if string(d) != "value" {
|
|
t.Errorf("Get failed: got %s, want %s", d, "value")
|
|
}
|
|
|
|
if d, err := sc.vfs.Get("key1"); err != nil {
|
|
t.Errorf("Get failed: %v", err)
|
|
} else if string(d) != "value1" {
|
|
t.Errorf("Get failed: got %s, want %s", d, "value1")
|
|
}
|
|
|
|
if d, err := sc.vfs.Get("key2"); err != nil {
|
|
t.Errorf("Get failed: %v", err)
|
|
} else if string(d) != "value2" {
|
|
t.Errorf("Get failed: got %s, want %s", d, "value2")
|
|
}
|
|
|
|
if sc.diskgc.Size() != 17 {
|
|
t.Errorf("Size failed: got %d, want %d", sc.diskgc.Size(), 17)
|
|
}
|
|
|
|
if sc.vfs.Size() != 17 {
|
|
t.Errorf("Size failed: got %d, want %d", sc.vfs.Size(), 17)
|
|
}
|
|
|
|
sc.memory.Delete("key2")
|
|
os.Remove(filepath.Join(td, "key2"))
|
|
|
|
if _, err := sc.vfs.Get("key2"); err == nil {
|
|
t.Errorf("Get failed: got nil, want error")
|
|
}
|
|
}
|