package helpers import ( "testing" "github.com/dmitriygnatenko/internal/models" ut "github.com/go-playground/universal-translator" "github.com/go-playground/validator/v10" "github.com/stretchr/testify/assert" ) func Test_FormatValidateErrors(t *testing.T) { type req struct { errors error trans ut.Translator } var ( form = models.TagForm{} validate = validator.New() trans, _ = GetDefaultTranslator(validate) correctErrors = validate.Struct(form) correctRes = map[string]string{ "TagForm.Tag": "Тег обязательное поле", "TagForm.URL": "URL обязательное поле", } ) tests := []struct { name string req req res map[string]string }{ { name: "empty request", req: req{}, res: map[string]string{}, }, { name: "positive case", req: req{ errors: correctErrors, trans: trans, }, res: correctRes, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { res := FormatValidateErrors(tt.req.errors, tt.req.trans) assert.Equal(t, tt.res, res) }) } }