Files
gotea/modules/validation/glob_pattern_test.go
T
lotherk 1b490485ff refactor: import Gotea from Gitea v28.4.0
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
2026-11-22 12:13:09 +00:00

57 lines
1.1 KiB
Go

// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package validation
import (
"testing"
"gotea.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)
})
}
}