mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 11:16:37 +08:00
0aff87c69d
优化
32 lines
874 B
Go
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)
|
|
}
|
|
}
|