mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-18 21:05:43 +00:00
7ebb2caa9e
Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package validation
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type (
|
|
validationTestCase struct {
|
|
description string
|
|
data any
|
|
expectedErrors BindingErrors
|
|
}
|
|
|
|
TestForm struct {
|
|
BranchName string `form:"BranchName" binding:"GitRefName"`
|
|
URL string `form:"ValidUrl" binding:"ValidUrl"`
|
|
GlobPattern string `form:"GlobPattern" binding:"GlobPattern"`
|
|
RegexPattern string `form:"RegexPattern" binding:"RegexPattern"`
|
|
Email string `form:"Email" binding:"Email"`
|
|
}
|
|
)
|
|
|
|
func performValidationTest(t *testing.T, testCase validationTestCase) {
|
|
assert.Equal(t, testCase.expectedErrors, Binder().Validate(t.Context(), testCase.data))
|
|
}
|
|
|
|
func TestEmailValidation(t *testing.T) {
|
|
assert.Nil(t, Binder().Validate(t.Context(), &TestForm{Email: "b@a"}))
|
|
assert.Equal(t, BindingErrors{{FieldNames: []string{"Email"}, Classification: "EmailError", Message: "invalid email"}},
|
|
Binder().Validate(t.Context(), &TestForm{Email: "abc"}))
|
|
}
|