trans_test.go 814 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package helpers
  2. import (
  3. "testing"
  4. "github.com/go-playground/locales/ru"
  5. ut "github.com/go-playground/universal-translator"
  6. "github.com/go-playground/validator/v10"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func Test_GetDefaultTranslator(t *testing.T) {
  10. var (
  11. validate = validator.New()
  12. localeRu = ru.New()
  13. uniTrans = ut.New(localeRu, localeRu)
  14. translator, _ = uniTrans.GetTranslator(localeRu.Locale())
  15. )
  16. tests := []struct {
  17. name string
  18. req *validator.Validate
  19. res ut.Translator
  20. err error
  21. }{
  22. {
  23. name: "positive case",
  24. req: validate,
  25. res: translator,
  26. err: nil,
  27. },
  28. }
  29. for _, tt := range tests {
  30. t.Run(tt.name, func(t *testing.T) {
  31. res, err := GetDefaultTranslator(tt.req)
  32. assert.IsType(t, tt.res, res)
  33. assert.Equal(t, tt.err, err)
  34. })
  35. }
  36. }