Files
MeBox/internal/service/cloud115/url_cache_test.go
T
truewhile 0aff87c69d 优化
优化
2026-08-24 17:00:18 +08:00

32 lines
874 B
Go

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)
}
}