45 lines
811 B
Go
45 lines
811 B
Go
![]() |
package controller
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"penahub.gitlab.yandexcloud.net/backend/templategen_feedback/internal/models"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type testStruct struct {
|
||
|
Name string `json:"name" validate:"required"`
|
||
|
}
|
||
|
|
||
|
func Test_validateStruct(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args *testStruct
|
||
|
want []*models.RespErrorValidate
|
||
|
}{
|
||
|
{
|
||
|
name: "filled struct",
|
||
|
args: &testStruct{Name: "John Doe"},
|
||
|
want: nil,
|
||
|
},
|
||
|
{
|
||
|
name: "struct with empty required",
|
||
|
args: &testStruct{
|
||
|
Name: "",
|
||
|
},
|
||
|
want: []*models.RespErrorValidate{
|
||
|
{
|
||
|
Field: "name",
|
||
|
Tag: "required",
|
||
|
Value: "",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
got := validateStruct(tt.args)
|
||
|
assert.Equal(t, tt.want, got)
|
||
|
})
|
||
|
}
|
||
|
}
|