MCPcopy
hub / github.com/kubernetes/kubectl / TestSetCustomLoadTranslationsFunc

Function TestSetCustomLoadTranslationsFunc

pkg/util/i18n/i18n_test.go:238–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

236}
237
238func TestSetCustomLoadTranslationsFunc(t *testing.T) {
239 resetLazyLoading()
240
241 // Set a custom translations func that loads translations from a directory
242 err := SetLoadTranslationsFunc(func() error {
243 gettext.BindLocale(gettext.New("k8s", "./translations/test"))
244 gettext.SetDomain("k8s")
245 gettext.SetLanguage("en_US")
246 return nil
247 })
248 if err != nil {
249 t.Errorf("unexpected error: %v", err)
250 }
251 if translationsLoaded {
252 t.Errorf("expected translationsLoaded to be false, but it was true")
253 }
254
255 // Translation should succeed
256 result := T("test_string")
257 if result != "baz" {
258 t.Errorf("expected: %s, saw: %s", "baz", result)
259 }
260 if !translationsLoaded {
261 t.Errorf("expected translationsLoaded to be true, but it was false")
262 }
263}
264
265func TestSetCustomLoadTranslationsFuncAfterTranslationsLoadedShouldFail(t *testing.T) {
266 resetLazyLoading()

Callers

nothing calls this directly

Calls 3

resetLazyLoadingFunction · 0.85
SetLoadTranslationsFuncFunction · 0.85
TFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…