(t *testing.T)
| 173 | } |
| 174 | |
| 175 | func TestFrom(t *testing.T) { |
| 176 | t.Parallel() |
| 177 | testCases := []struct { |
| 178 | From string |
| 179 | Match string |
| 180 | }{ |
| 181 | {"1", "1"}, |
| 182 | {"kyle@kwc.io", "kyle"}, |
| 183 | {"kyle+wow@kwc.io", "kylewow"}, |
| 184 | {"kyle+testing", "kyletesting"}, |
| 185 | {"kyle-testing", "kyle-testing"}, |
| 186 | {"much.”more unusual”@example.com", "muchmoreunusual"}, |
| 187 | |
| 188 | // Cases where an invalid string is provided, and the result is a random name. |
| 189 | {"123456789012345678901234567890123", ""}, |
| 190 | {"very.unusual.”@”.unusual.com@example.com", ""}, |
| 191 | {"___@ok.com", ""}, |
| 192 | {" something with spaces ", ""}, |
| 193 | {"--test--", ""}, |
| 194 | {"", ""}, |
| 195 | } |
| 196 | for _, testCase := range testCases { |
| 197 | t.Run(testCase.From, func(t *testing.T) { |
| 198 | t.Parallel() |
| 199 | converted := codersdk.UsernameFrom(testCase.From) |
| 200 | t.Log(converted) |
| 201 | valid := codersdk.NameValid(converted) |
| 202 | require.True(t, valid == nil) |
| 203 | if testCase.Match == "" { |
| 204 | require.NotEqual(t, testCase.From, converted) |
| 205 | } else { |
| 206 | require.Equal(t, testCase.Match, converted) |
| 207 | } |
| 208 | }) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | func TestUserRealNameValid(t *testing.T) { |
| 213 | t.Parallel() |
nothing calls this directly
no test coverage detected