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)。 本次为公开发布初始提交:完整开发历史(含部署细节)留存于私有归档,公开仓库自此干净起步。
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package platform
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestConfigRoundTrip(t *testing.T) {
|
|
// Redirect the user config dir into a temp HOME so the test never touches
|
|
// the real ~/Library/Application Support.
|
|
t.Setenv("HOME", t.TempDir())
|
|
|
|
// Absent file → defaults.
|
|
got, err := LoadConfig()
|
|
if err != nil {
|
|
t.Fatalf("LoadConfig (absent): %v", err)
|
|
}
|
|
if got != DefaultConfig() {
|
|
t.Errorf("absent config should be defaults, got %+v", got)
|
|
}
|
|
|
|
want := DesktopConfig{ClipboardSyncEnabled: false, LaunchAtLogin: true}
|
|
if err := SaveConfig(want); err != nil {
|
|
t.Fatalf("SaveConfig: %v", err)
|
|
}
|
|
got, err = LoadConfig()
|
|
if err != nil {
|
|
t.Fatalf("LoadConfig: %v", err)
|
|
}
|
|
if got != want {
|
|
t.Errorf("round-trip: got %+v, want %+v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigToleratesGarbage(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
p, err := configPath()
|
|
if err != nil {
|
|
t.Fatalf("configPath: %v", err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(p, []byte("{not json"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := LoadConfig()
|
|
if err == nil {
|
|
t.Error("expected an error for malformed json")
|
|
}
|
|
if got != DefaultConfig() {
|
|
t.Errorf("malformed config should fall back to defaults, got %+v", got)
|
|
}
|
|
}
|