mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-20 02:19:45 +09:00
Better than before, still not good enough (more work can be done in the future) And add the missing error handling in the PrivateContext "bind" middleware. By the way, picked some "TrimSpace" changes from "fix: trim whitespace from SMTP address and port - #38934" (fix #38926)
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package validation
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dev/modules/glob"
|
|
)
|
|
|
|
func getGlobPatternErrorString(pattern string) string {
|
|
// It would be unwise to rely on that glob
|
|
// compilation errors don't ever change.
|
|
if _, err := glob.Compile(pattern); err != nil {
|
|
return err.Error()
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func Test_GlobPatternValidation(t *testing.T) {
|
|
globValidationTestCases := []validationTestCase{
|
|
{
|
|
description: "Empty glob pattern",
|
|
data: &TestForm{
|
|
GlobPattern: "",
|
|
},
|
|
},
|
|
{
|
|
description: "Valid glob",
|
|
data: &TestForm{
|
|
GlobPattern: "{master,release*}",
|
|
},
|
|
},
|
|
|
|
{
|
|
description: "Invalid glob",
|
|
data: &TestForm{
|
|
GlobPattern: "[a-",
|
|
},
|
|
expectedErrors: BindingErrors{
|
|
BindingError{
|
|
FieldNames: []string{"GlobPattern"},
|
|
Classification: ErrGlobPattern,
|
|
Message: getGlobPatternErrorString("[a-"),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, testCase := range globValidationTestCases {
|
|
t.Run(testCase.description, func(t *testing.T) {
|
|
performValidationTest(t, testCase)
|
|
})
|
|
}
|
|
}
|