test(quick-261016-0fm): admin preference coverage

- Translator.Locales: sorted, prefix-scoped, nil-safe
- preferencesOf, validPreferences, refused keys, metadata writes and
  principalFrom's PreferredLocale (internal, Docker-free)
- Docker: refused keys and values leave the row alone, owner-only saves,
  personal tokens get interactive_only and keep the request locale, the
  cookie CSRF header, non-object metadata stays byte-identical
This commit is contained in:
Jakub Zych
2026-10-16 11:44:32 +02:00
parent 85e52d9336
commit 119f1f8d54
3 changed files with 331 additions and 0 deletions

View File

@@ -343,3 +343,31 @@ func TestCatalogBoundaries(t *testing.T) {
}
})
}
func TestTranslatorLocales(t *testing.T) {
t.Parallel()
fsys := fstest.MapFS{
"lang/pl/lang.yaml": {Data: []byte("greeting: Cześć\n")},
"lang/en/lang.yaml": {Data: []byte("greeting: Hello\n")},
"lang/de/other.yaml": {Data: []byte("greeting: Hallo\n")},
}
cat := NewCatalog()
if err := cat.Load("acme.blog", fsys); err != nil {
t.Fatalf("Load: %v", err)
}
tr := NewTranslator(cat, Options{})
if got := tr.Locales("acme.blog::lang."); strings.Join(got, ",") != "en,pl" {
t.Fatalf("Locales(lang) = %v, want [en pl]", got)
}
if got := tr.Locales("acme.blog::"); strings.Join(got, ",") != "de,en,pl" {
t.Fatalf("Locales(namespace) = %v, want [de en pl]", got)
}
if got := tr.Locales("acme.shop::"); len(got) != 0 {
t.Fatalf("Locales(unknown) = %v, want none", got)
}
var nilTr *Translator
if got := nilTr.Locales("acme.blog::"); got != nil {
t.Fatalf("nil translator Locales = %v, want nil", got)
}
}