2015-03-24 07:25:26 -04:00
|
|
|
package stringid
|
2015-02-25 13:27:14 -05:00
|
|
|
|
2015-04-10 13:09:08 -04:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
2015-03-24 07:25:26 -04:00
|
|
|
|
|
|
|
func TestGenerateRandomID(t *testing.T) {
|
|
|
|
id := GenerateRandomID()
|
|
|
|
|
|
|
|
if len(id) != 64 {
|
|
|
|
t.Fatalf("Id returned is incorrect: %s", id)
|
|
|
|
}
|
|
|
|
}
|
2015-02-25 13:27:14 -05:00
|
|
|
|
|
|
|
func TestShortenId(t *testing.T) {
|
|
|
|
id := GenerateRandomID()
|
|
|
|
truncID := TruncateID(id)
|
|
|
|
if len(truncID) != 12 {
|
|
|
|
t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShortenIdEmpty(t *testing.T) {
|
|
|
|
id := ""
|
|
|
|
truncID := TruncateID(id)
|
|
|
|
if len(truncID) > len(id) {
|
|
|
|
t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShortenIdInvalid(t *testing.T) {
|
|
|
|
id := "1234"
|
|
|
|
truncID := TruncateID(id)
|
|
|
|
if len(truncID) != len(id) {
|
|
|
|
t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID)
|
|
|
|
}
|
|
|
|
}
|
2015-04-10 13:09:08 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|