You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read the docs on validating, and spotted a test, and example for an auth handler in another test of adding validation.
But when I specify validation for my endpoint, Encore doesn't seem to be going through validation when I call it in my test.
My code:
typeCreateUserRequeststruct {
Emailstring`json:"email" validate:"required"`FirstNamestring`json:"first_name" validate:"required"`
}
// Validate is applied to the request by encore in the middleware before it is passed to the API function.func (req*CreateUserRequest) Validate() error {
validate:=validator.New(validator.WithRequiredStructEnabled())
log.Println("validating struct")
returnvalidate.Struct(req)
}
// Create creates a user////encore:api auth method=POST path=/users/createfunc (s*Service) CreateUser(ctx context.Context, req*CreateUserRequest) (res*CreateUserResponse, errerror) {
...
I don't see the validation happening, and also don't see my log line in the logs.
EDIT: I notice that it is validating in my live application, but just not from my test, when I run:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have read the docs on validating, and spotted a test, and example for an auth handler in another test of adding validation.
But when I specify validation for my endpoint, Encore doesn't seem to be going through validation when I call it in my test.
My code:
I don't see the validation happening, and also don't see my log line in the logs.
EDIT: I notice that it is validating in my live application, but just not from my test, when I run:
Do I need to call it in a different way in order to get the validation to be applied in tests?
Help would be greatly appreciated!
Thanks
Beta Was this translation helpful? Give feedback.
All reactions