f21fa5b5e8
Commilitia Drop:自托管的跨设备剪贴板同步与点对点文件传输。 - 后端 Go(chi / SQLite WAL / SSE Hub / WebRTC signaling + 状态机 / Relay ring buffer),编译进单个 distroless 镜像(前端 go:embed)。 - 前端 React + TanStack Router + Zustand,自实现 SSE + WebRTC P2P,NAT 受阻时回退服务端中继;聚珍(Juzhen)CJK 综合排版。 - 桌面端 Wails v2(macOS / Windows),瘦客户端复用 web。 - 鉴权 OIDC PKCE(自建 Casdoor 等),refresh_token 信封加密存系统密钥库;iOS Shortcut 用 HS256 scoped token。 架构文档与变更记录见 docs 分支(PROJECT_BRIEF / FRONTEND_DESIGN / CHANGELOG)。 本次为公开发布初始提交:完整开发历史(含部署细节)留存于私有归档,公开仓库自此干净起步。
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package calls
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// The refresh margin scales with the TTL (a quarter, floored at 5m) so a short
|
|
// R3 TTL still leaves every served credential a comfortable validity window
|
|
// without refetching on every call.
|
|
func TestNewProvider_RefreshMargin(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
ttl time.Duration
|
|
want time.Duration
|
|
}{
|
|
{"default when zero", 0, DefaultTTL / 4}, // ttl<=0 → DefaultTTL (1h) → 15m
|
|
{"one hour", time.Hour, 15 * time.Minute}, // quarter
|
|
{"quarter floored at 5m", 10 * time.Minute, 5 * time.Minute}, // 2.5m → floor 5m, 5m<10m
|
|
{"pathologically short", 4 * time.Minute, 2 * time.Minute}, // floor 5m >= 4m ttl → ttl/2
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
p := NewProvider("k", "tok", c.ttl)
|
|
if p.refreshMargin != c.want {
|
|
t.Errorf("refreshMargin: got %v, want %v", p.refreshMargin, c.want)
|
|
}
|
|
if p.refreshMargin >= p.ttl {
|
|
t.Errorf("margin %v must stay under ttl %v so the cache can serve", p.refreshMargin, p.ttl)
|
|
}
|
|
})
|
|
}
|
|
}
|