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

Function TestFrom

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

Source from the content-addressed store, hash-verified

173}
174
175func 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
212func TestUserRealNameValid(t *testing.T) {
213 t.Parallel()

Callers

nothing calls this directly

Calls 5

UsernameFromFunction · 0.92
NameValidFunction · 0.92
LogMethod · 0.80
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected