fix(cloudid): avoid use invalid character for role name

This commit is contained in:
Qu Xuan
2020-11-26 21:36:59 +08:00
parent c64d98f769
commit fd948b8cc5
3 changed files with 62 additions and 1 deletions

View File

@@ -208,3 +208,32 @@ func TestGetCharTypeCount(t *testing.T) {
}
}
}
func TestRoleName(t *testing.T) {
cases := []struct {
in string
want string
random bool
length int
}{
{
in: "小琪",
random: true,
length: 17,
},
{
in: "123^567",
want: "123567",
},
}
for _, c := range cases {
got := GenerateRoleName(c.in)
if c.random {
if len(got) != c.length {
t.Errorf("GenerateRoleName %s random want %d length got %d(%s)", c.in, c.length, len(got), got)
}
} else if got != c.want {
t.Errorf("GenerateRoleName %s want %s got %s", c.in, c.want, got)
}
}
}