2018-02-15 02:56:13 -06:00
|
|
|
package util
|
|
|
|
|
2021-09-10 04:22:13 -05:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
2018-02-15 02:56:13 -06:00
|
|
|
|
|
|
|
func TestAllowedCharMatchesUidPattern(t *testing.T) {
|
|
|
|
for _, c := range allowedChars {
|
2019-01-28 15:37:44 -06:00
|
|
|
if !IsValidShortUID(string(c)) {
|
2018-02-15 02:56:13 -06:00
|
|
|
t.Fatalf("charset for creating new shortids contains chars not present in uid pattern")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 04:22:13 -05:00
|
|
|
|
|
|
|
func TestIsShortUIDTooLong(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
|
|
|
uid string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "when the length of uid is longer than 40 chars then IsShortUIDTooLong should return true",
|
|
|
|
uid: allowedChars,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "when the length of uid is equal too 40 chars then IsShortUIDTooLong should return false",
|
|
|
|
uid: "0123456789012345678901234567890123456789",
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "when the length of uid is shorter than 40 chars then IsShortUIDTooLong should return false",
|
|
|
|
uid: "012345678901234567890123456789012345678",
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
require.Equal(t, tt.expected, IsShortUIDTooLong(tt.uid))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|