MCPcopy Index your code
hub / github.com/coder/coder / TestUsernameValid

Function TestUsernameValid

codersdk/name_test.go:15–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestUsernameValid(t *testing.T) {
16 t.Parallel()
17 // Tests whether usernames are valid or not.
18 testCases := []struct {
19 Username string
20 Valid bool
21 }{
22 {"1", true},
23 {"12", true},
24 {"123", true},
25 {"12345678901234567890", true},
26 {"123456789012345678901", true},
27 {"a", true},
28 {"a1", true},
29 {"a1b2", true},
30 {"a1b2c3d4e5f6g7h8i9j0", true},
31 {"a1b2c3d4e5f6g7h8i9j0k", true},
32 {"aa", true},
33 {"abc", true},
34 {"abcdefghijklmnopqrst", true},
35 {"abcdefghijklmnopqrstu", true},
36 {"wow-test", true},
37
38 {"", false},
39 {" ", false},
40 {" a", false},
41 {" a ", false},
42 {" 1", false},
43 {"1 ", false},
44 {" aa", false},
45 {"aa ", false},
46 {" 12", false},
47 {"12 ", false},
48 {" a1", false},
49 {"a1 ", false},
50 {" abcdefghijklmnopqrstu", false},
51 {"abcdefghijklmnopqrstu ", false},
52 {" 123456789012345678901", false},
53 {" a1b2c3d4e5f6g7h8i9j0k", false},
54 {"a1b2c3d4e5f6g7h8i9j0k ", false},
55 {"bananas_wow", false},
56 {"test--now", false},
57
58 {"123456789012345678901234567890123", false},
59 {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false},
60 {"123456789012345678901234567890123123456789012345678901234567890123", false},
61 }
62 for _, testCase := range testCases {
63 t.Run(testCase.Username, func(t *testing.T) {
64 t.Parallel()
65 valid := codersdk.NameValid(testCase.Username)
66 require.Equal(t, testCase.Valid, valid == nil)
67 })
68 }
69}
70
71func TestTemplateDisplayNameValid(t *testing.T) {
72 t.Parallel()

Callers

nothing calls this directly

Calls 3

NameValidFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected