Merge pull request #48706 from thaJeztah/stringid_optimize

pkg/stringid: optimize GenerateRandomID
This commit is contained in:
Sebastiaan van Stijn
2024-10-21 16:53:04 +02:00
committed by GitHub
2 changed files with 53 additions and 6 deletions

View File

@@ -54,3 +54,33 @@ func TestTruncateID(t *testing.T) {
})
}
}
func TestAllNum(t *testing.T) {
tests := []struct {
doc, id string
expected bool
}{
{
doc: "mixed letters and numbers",
id: "4e38e38c8ce0",
expected: false,
},
{
doc: "letters only",
id: "deadbeefcafe",
expected: false,
},
{
doc: "numbers only",
id: "012345678912",
expected: true,
},
}
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
if actual := allNum(tc.id); actual != tc.expected {
t.Errorf("expected %q to be %t, got %t, ", tc.id, !tc.expected, actual)
}
})
}
}