|
@@ -1,6 +1,9 @@
|
|
|
package stringid
|
|
|
|
|
|
-import "testing"
|
|
|
+import (
|
|
|
+ "strings"
|
|
|
+ "testing"
|
|
|
+)
|
|
|
|
|
|
func TestGenerateRandomID(t *testing.T) {
|
|
|
id := GenerateRandomID()
|
|
@@ -33,3 +36,21 @@ func TestShortenIdInvalid(t *testing.T) {
|
|
|
t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestIsShortIDNonHex(t *testing.T) {
|
|
|
+ id := "some non-hex value"
|
|
|
+ if IsShortID(id) {
|
|
|
+ t.Fatalf("%s is not a short ID", id)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestIsShortIDNotCorrectSize(t *testing.T) {
|
|
|
+ id := strings.Repeat("a", shortLen+1)
|
|
|
+ if IsShortID(id) {
|
|
|
+ t.Fatalf("%s is not a short ID", id)
|
|
|
+ }
|
|
|
+ id = strings.Repeat("a", shortLen-1)
|
|
|
+ if IsShortID(id) {
|
|
|
+ t.Fatalf("%s is not a short ID", id)
|
|
|
+ }
|
|
|
+}
|