- 品牌: Go 模块/数据文件/二进制/构建部署资产全部 opsx→lokistack;前端 localStorage 命名空间迁移(读旧写新,含按用户 id 前缀迁移);修复 nginx upstream 与 Makefile 引用已改名服务的断裂 - i18n: react-i18next 落地,common + 11 个页面域命名空间全站中英(菜单/顶栏/登录/列表页/表单/确认弹窗/状态徽章);设置页语言即时切换;修复词典自注册导致的循环导入白屏 - 用户管理: 批量删除(POST /users/batch-delete,不删自己/最后管理员,部分失败不阻断)+ 行复选/全选/批量工具条 - 主题: 浅色侧栏(中性灰激活态)、四态模式(浅色/深色/跟随系统/定时切换,按时区判定)、顶栏太阳月亮二态、设置页紧凑分段选择器 - UI: 登录记住用户名、CardActionButton 统一五页卡片操作钮、shadcn Badge 替换手写徽章、语义色修正 - 清理: 移除主机 Web 终端(前后端)、k8s-helm/Helm 遗留代码与字段、README 重写精简 - 修复: 侧栏与日志告警 order 重复、路由标题 i18n key 未翻译、词典双逗号等
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package services
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"lokistack/repository"
|
|
)
|
|
|
|
func TestParseRetentionYAML(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
source string
|
|
want int
|
|
}{
|
|
{"days", "limits_config:\n retention_period: 90d\n", 90},
|
|
{"hours", "limits_config:\n retention_period: 2160h\n", 90},
|
|
{"unknown field", "limits_config:\n retention_period: 90d\n ingestion_rate_mb: 16\n", 0},
|
|
{"fractional day", "limits_config:\n retention_period: 25h\n", 0},
|
|
{"extra document", "limits_config:\n retention_period: 90d\n---\nfoo: bar\n", 0},
|
|
{"missing field", "limits_config: {}\n", 0},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got, err := parseRetentionYAML(tc.source)
|
|
if tc.want == 0 && err == nil {
|
|
t.Fatalf("accepted invalid YAML: %q", tc.source)
|
|
}
|
|
if tc.want != 0 && (err != nil || got != tc.want) {
|
|
t.Fatalf("got %d, err %v; want %d", got, err, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDeploymentRetentionPersistsAndRejectsInvalidValues(t *testing.T) {
|
|
t.Setenv("DATA_DIR", t.TempDir())
|
|
t.Setenv("JWT_SECRET", "test-jwt-secret-with-at-least-32-characters")
|
|
t.Setenv("ENCRYPTION_KEY", "test-encryption-key-with-at-least-32-characters")
|
|
if err := repository.InitDB(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = repository.Shutdown() })
|
|
|
|
service := NewDeploymentService()
|
|
deployment, err := service.Create(&CreateDeploymentRequest{
|
|
Name: "loki", Mode: "k8s-yaml", Version: "3.0.0",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if deployment.RetentionDays != DefaultRetentionDays {
|
|
t.Fatalf("default retention = %d, want %d", deployment.RetentionDays, DefaultRetentionDays)
|
|
}
|
|
for _, invalid := range []float64{0, -1, 1.5} {
|
|
if err := service.Update(deployment.ID, map[string]interface{}{"retentionDays": invalid}); err == nil {
|
|
t.Fatalf("accepted invalid retention %v", invalid)
|
|
}
|
|
}
|
|
if err := service.Update(deployment.ID, map[string]interface{}{"retentionDays": float64(90)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
updated, err := service.Get(deployment.ID)
|
|
if err != nil || updated.RetentionDays != 90 {
|
|
t.Fatalf("updated retention = %v, err = %v", updated, err)
|
|
}
|
|
if err := repository.GetDB().RequestSaveSync(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|