mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 20:46:37 +08:00
优化
优化
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package cloud115
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDownloadURLCache(t *testing.T) {
|
||||
urlCacheMu.Lock()
|
||||
urlCache = map[string]urlCacheEntry{}
|
||||
urlCacheMu.Unlock()
|
||||
|
||||
if got := GetDownloadURLCache("pick1"); got != "" {
|
||||
t.Fatalf("empty cache should return empty, got %q", got)
|
||||
}
|
||||
SetDownloadURLCache("pick1", "http://cdn/1")
|
||||
if got := GetDownloadURLCache("pick1"); got != "http://cdn/1" {
|
||||
t.Fatalf("cache miss, got %q", got)
|
||||
}
|
||||
// 过期条目按未命中处理
|
||||
urlCacheMu.Lock()
|
||||
urlCache["pick1"] = urlCacheEntry{url: "http://cdn/old", expiresAt: time.Now().Add(-time.Second)}
|
||||
urlCacheMu.Unlock()
|
||||
if got := GetDownloadURLCache("pick1"); got != "" {
|
||||
t.Fatalf("expired entry should be a miss, got %q", got)
|
||||
}
|
||||
ClearDownloadURLCache("pick1")
|
||||
if got := GetDownloadURLCache("pick1"); got != "" {
|
||||
t.Fatalf("cleared entry should be a miss, got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user