11package mutator
22
3- import "testing"
3+ import (
4+ "testing"
5+
6+ "github.com/stretchr/testify/assert"
7+ )
48
59func TestPopulateCurrentUser (t * testing.T ) {
610 // We need to implement workspace client mocking to implement this test.
@@ -13,28 +17,60 @@ func TestGetShortUserName(t *testing.T) {
1317 expected string
1418 }{
1519 {
16- name : "test alphanumeric characters" ,
17- 18- expected : "test_user" ,
20+ 21+ expected : "test_user_1234" ,
1922 },
2023 {
21- name : "test unicode characters" ,
22242325 expected : "tést_üser" ,
2426 },
2527 {
26- name : "test special characters" ,
27282829 expected : "test__user" ,
2930 },
31+ {
32+ email : `jöhn.dœ@domain.com` , // Using non-ASCII characters.
33+ expected : "jöhn_dœ" ,
34+ },
35+ {
36+ email :
`[email protected] ` ,
// The plus (+) sign is used for "sub-addressing" in some email services. 37+ expected : "first_tag" ,
38+ },
39+ {
40+ email :
`[email protected] ` ,
// Using a sub-domain. 41+ expected : "email" ,
42+ },
43+ {
44+ email : `"_quoted"@domain.com` , // Quoted strings can be part of the local-part.
45+ expected : "__quoted_" ,
46+ },
47+ {
48+ email :
`name-o'[email protected] ` ,
// Single quote in the local-part. 49+ expected : "name_o_mally" ,
50+ },
51+ {
52+ email :
`user%[email protected] ` ,
// Percent sign can be used for email routing in legacy systems. 53+ expected : "user_domain" ,
54+ },
55+ {
56+ email :
`[email protected] ` ,
// Multiple dots in the local-part. 57+ expected : "long_name_with_dots" ,
58+ },
59+ {
60+ email :
`me&[email protected] ` ,
// Using an ampersand (&) in the local-part. 61+ expected : "me_you" ,
62+ },
63+ {
64+ email :
`[email protected] ` ,
// The exclamation mark can be valid in some legacy systems. 65+ expected : "user_def_xyz" ,
66+ },
67+ {
68+ email : `admin@ιντερνετ.com` , // Domain in non-ASCII characters (IDN or Internationalized Domain Name).
69+ expected : "admin" ,
70+ },
3071 }
3172
3273 for _ , tt := range tests {
33- t .Run (tt .name , func (t * testing.T ) {
34- result := getShortUserName (tt .email )
35- if result != tt .expected {
36- t .Errorf ("getShortUserName(%q) = %q; expected %q" , tt .email , result , tt .expected )
37- }
38- })
74+ assert .Equal (t , tt .expected , getShortUserName (tt .email ))
3975 }
4076}
0 commit comments