* Move repository package to apps
* Move operators to grafana/grafana
* Go mod tidy
* Own package by git sync team for now
* Merged
* Do not use settings in local extra
* Remove dependency on webhook extra
* Hack to work around issue with secure contracts
* Sync Go modules
* Revert "Move operators to grafana/grafana"
This reverts commit 9f19b30a2e.
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package git
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsValidGitBranchName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
branch string
|
|
expected bool
|
|
}{
|
|
{"Valid branch name", "feature/add-tests", true},
|
|
{"Valid branch name with numbers", "feature/123-add-tests", true},
|
|
{"Valid branch name with dots", "feature.add.tests", true},
|
|
{"Valid branch name with hyphens", "feature-add-tests", true},
|
|
{"Valid branch name with underscores", "feature_add_tests", true},
|
|
{"Valid branch name with mixed characters", "feature/add_tests-123", true},
|
|
{"Starts with /", "/feature", false},
|
|
{"Ends with /", "feature/", false},
|
|
{"Ends with .", "feature.", false},
|
|
{"Ends with space", "feature ", false},
|
|
{"Contains consecutive slashes", "feature//branch", false},
|
|
{"Contains consecutive dots", "feature..branch", false},
|
|
{"Contains @{", "feature@{branch", false},
|
|
{"Contains invalid character ~", "feature~branch", false},
|
|
{"Contains invalid character ^", "feature^branch", false},
|
|
{"Contains invalid character :", "feature:branch", false},
|
|
{"Contains invalid character ?", "feature?branch", false},
|
|
{"Contains invalid character *", "feature*branch", false},
|
|
{"Contains invalid character [", "feature[branch", false},
|
|
{"Contains invalid character ]", "feature]branch", false},
|
|
{"Contains invalid character \\", "feature\\branch", false},
|
|
{"Empty branch name", "", false},
|
|
{"Only whitespace", " ", false},
|
|
{"Single valid character", "a", true},
|
|
{"Ends with .lock", "feature.lock", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.expected, IsValidGitBranchName(tt.branch))
|
|
})
|
|
}
|
|
}
|