Use constants in test

This commit is contained in:
Paul Tyng 2018-03-10 20:56:13 -05:00 committed by GitHub
parent f18e4f2921
commit 707d7febe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -15,8 +15,6 @@ func TestUniqueId(t *testing.T) {
return rest[:18], rest[18:] return rest[:18], rest[18:]
} }
const prefix = "terraform-"
iterations := 10000 iterations := 10000
ids := make(map[string]struct{}) ids := make(map[string]struct{})
var id, lastId string var id, lastId string
@ -27,13 +25,13 @@ func TestUniqueId(t *testing.T) {
t.Fatalf("Got duplicated id! %s", id) t.Fatalf("Got duplicated id! %s", id)
} }
if !strings.HasPrefix(id, prefix) { if !strings.HasPrefix(id, UniqueIdPrefix) {
t.Fatalf("Unique ID didn't have terraform- prefix! %s", id) t.Fatalf("Unique ID didn't have terraform- prefix! %s", id)
} }
rest := strings.TrimPrefix(id, prefix) rest := strings.TrimPrefix(id, UniqueIdPrefix)
if len(rest) != 26 { if len(rest) != UniqueIDSuffixLength {
t.Fatalf("Post-prefix part has wrong length! %s", rest) t.Fatalf("Post-prefix part has wrong length! %s", rest)
} }
@ -58,8 +56,8 @@ func TestUniqueId(t *testing.T) {
id1 := UniqueId() id1 := UniqueId()
time.Sleep(time.Millisecond) time.Sleep(time.Millisecond)
id2 := UniqueId() id2 := UniqueId()
timestamp1, _ := split(strings.TrimPrefix(id1, prefix)) timestamp1, _ := split(strings.TrimPrefix(id1, UniqueIdPrefix))
timestamp2, _ := split(strings.TrimPrefix(id2, prefix)) timestamp2, _ := split(strings.TrimPrefix(id2, UniqueIdPrefix))
if timestamp1 == timestamp2 { if timestamp1 == timestamp2 {
t.Fatalf("Timestamp part should update at least once a millisecond %s %s", t.Fatalf("Timestamp part should update at least once a millisecond %s %s",