Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
29 lines
843 B
Go
29 lines
843 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package middleware
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gotea.dev/modules/translation"
|
|
"gotea.dev/modules/validation"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type testRangeForm struct {
|
|
FormDefaultValidator
|
|
Hours int `binding:"Range(0,1000)"`
|
|
}
|
|
|
|
func TestBuildValidationErrorForUser(t *testing.T) {
|
|
// an out-of-range value must reach its own message instead of the panicking "default" branch
|
|
form := &testRangeForm{Hours: 2000}
|
|
errs := validation.Binder().Validate(t.Context(), form)
|
|
errorMessage, errorFieldName, fieldNames := BuildValidationErrorForUser(form, translation.MockLocale{}, errs)
|
|
assert.Equal(t, "form.range_error:form.Hours,0,1000", errorMessage)
|
|
assert.Equal(t, "Hours", errorFieldName)
|
|
assert.Equal(t, []string{"Hours"}, fieldNames)
|
|
}
|