feat(config): [database] deployment 指向集群内的数据库

This commit is contained in:
Lemon-miaow committed 2026-09-26 12:03:23 +08:00
1 parent b4737f4682
commit a20840e7d8
2 files changed
+34

No files matched your search

+19
View File
@@ -171,6 +171,25 @@ root_domain = "mc.example.net"
}
}
func TestLoadDatabaseDeployment(t *testing.T) {
withDeployment := func(v string) string {
return strings.Replace(validTOML, `url = "postgres://felis:secret@db:5432/felis"`,
`url = "postgres://felis:secret@db:5432/felis"`+"\ndeployment = \""+v+"\"", 1)
}
cfg, err := config.Load(writeTOML(t, withDeployment("felis/felis-postgres")))
if err != nil {
t.Fatalf("Load: %v", err)
}
if cfg.Database.Deployment != "felis/felis-postgres" {
t.Fatalf("deployment = %q", cfg.Database.Deployment)
}
for _, bad := range []string{"felis-postgres", "felis/", "/felis-postgres", "Felis/pg", "felis/pg; rm -rf /", "a/b/c"} {
if _, err := config.Load(writeTOML(t, withDeployment(bad))); err == nil || !strings.Contains(err.Error(), "namespace/name") {
t.Errorf("deployment %q: err = %v, want a namespace/name refusal", bad, err)
}
}
}
func TestLoadRejectsMissingRootDomain(t *testing.T) {
_, err := config.Load(writeTOML(t, `
[database]