diff options
Diffstat (limited to 'internal/validate/username_test.go')
| -rw-r--r-- | internal/validate/username_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/validate/username_test.go b/internal/validate/username_test.go new file mode 100644 index 00000000..1970fa4a --- /dev/null +++ b/internal/validate/username_test.go @@ -0,0 +1,30 @@ +package validate_test + +import ( + "strings" + "testing" + + "hakurei.app/internal/validate" +) + +func TestIsValidUsername(t *testing.T) { + t.Parallel() + + t.Run("long", func(t *testing.T) { + if validate.IsValidUsername(strings.Repeat("a", validate.Sysconf(validate.SC_LOGIN_NAME_MAX))) { + t.Errorf("IsValidUsername unexpected true") + } + }) + + t.Run("regexp", func(t *testing.T) { + if validate.IsValidUsername("0") { + t.Errorf("IsValidUsername unexpected true") + } + }) + + t.Run("valid", func(t *testing.T) { + if !validate.IsValidUsername("alice") { + t.Errorf("IsValidUsername unexpected false") + } + }) +} |
