mirror of
https://github.com/1f349/site-hosting.git
synced 2025-01-21 22:56:27 +00:00
67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
package validation
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsValidSite(t *testing.T) {
|
|
for _, i := range []struct {
|
|
s string
|
|
valid bool
|
|
}{
|
|
{"", false},
|
|
{"a", true},
|
|
{"abc", true},
|
|
{"0", true},
|
|
{"0123456789", true},
|
|
{"_", true},
|
|
{"_ab", true},
|
|
{"-", false},
|
|
{"-ab", false},
|
|
{".", true},
|
|
{".ab", true},
|
|
{"a-b", true},
|
|
{"a_b", true},
|
|
{"a/b", false},
|
|
{"a.b", true},
|
|
{"ab-", true},
|
|
{"ab_", true},
|
|
{"ab.", true},
|
|
{"/ab", false},
|
|
{"ab/", false},
|
|
} {
|
|
assert.Equal(t, i.valid, IsValidSite(i.s), "Test failed \"%s\" - %v", i.s, i.valid)
|
|
}
|
|
}
|
|
|
|
func TestIsValidBranch(t *testing.T) {
|
|
for _, i := range []struct {
|
|
s string
|
|
valid bool
|
|
}{
|
|
{"", false},
|
|
{"a", true},
|
|
{"abc", true},
|
|
{"0", true},
|
|
{"0123456789", true},
|
|
{"_", true},
|
|
{"_ab", true},
|
|
{"-", false},
|
|
{"-ab", false},
|
|
{".", true},
|
|
{".ab", true},
|
|
{"a-b", true},
|
|
{"a_b", true},
|
|
{"a/b", true},
|
|
{"a.b", true},
|
|
{"ab-", true},
|
|
{"ab_", true},
|
|
{"ab.", true},
|
|
{"/ab", false},
|
|
{"ab/", false},
|
|
} {
|
|
assert.Equal(t, i.valid, IsValidBranch(i.s), "Test failed \"%s\" - %v", i.s, i.valid)
|
|
}
|
|
}
|