aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/username_test.go
blob: 1b2e04599ec108825151e10f73ecd06375a72b2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package app

import (
	"strings"
	"testing"
)

func TestIsValidUsername(t *testing.T) {
	t.Parallel()

	t.Run("long", func(t *testing.T) {
		if isValidUsername(strings.Repeat("a", sysconf(_SC_LOGIN_NAME_MAX))) {
			t.Errorf("isValidUsername unexpected true")
		}
	})

	t.Run("regexp", func(t *testing.T) {
		if isValidUsername("0") {
			t.Errorf("isValidUsername unexpected true")
		}
	})

	t.Run("valid", func(t *testing.T) {
		if !isValidUsername("alice") {
			t.Errorf("isValidUsername unexpected false")
		}
	})
}