Merge pull request #17551 from hashicorp/paultyng-patch-1
Export a const for validation methods
This commit is contained in:
commit
9442c4b46e
|
@ -18,6 +18,11 @@ func UniqueId() string {
|
|||
return PrefixedUniqueId(UniqueIdPrefix)
|
||||
}
|
||||
|
||||
// UniqueIDSuffixLength is the string length of the suffix generated by
|
||||
// PrefixedUniqueId. This can be used by length validation functions to
|
||||
// ensure prefixes are the correct length for the target field.
|
||||
const UniqueIDSuffixLength = 26
|
||||
|
||||
// Helper for a resource to generate a unique identifier w/ given prefix
|
||||
//
|
||||
// After the prefix, the ID consists of an incrementing 26 digit value (to match
|
||||
|
|
|
@ -15,8 +15,6 @@ func TestUniqueId(t *testing.T) {
|
|||
return rest[:18], rest[18:]
|
||||
}
|
||||
|
||||
const prefix = "terraform-"
|
||||
|
||||
iterations := 10000
|
||||
ids := make(map[string]struct{})
|
||||
var id, lastId string
|
||||
|
@ -27,14 +25,14 @@ func TestUniqueId(t *testing.T) {
|
|||
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)
|
||||
}
|
||||
|
||||
rest := strings.TrimPrefix(id, prefix)
|
||||
rest := strings.TrimPrefix(id, UniqueIdPrefix)
|
||||
|
||||
if len(rest) != 26 {
|
||||
t.Fatalf("Post-prefix part has wrong length! %s", rest)
|
||||
if len(rest) != UniqueIDSuffixLength {
|
||||
t.Fatalf("PrefixedUniqueId is out of sync with UniqueIDSuffixLength, post-prefix part has wrong length! %s", rest)
|
||||
}
|
||||
|
||||
timestamp, increment := split(rest)
|
||||
|
@ -58,8 +56,8 @@ func TestUniqueId(t *testing.T) {
|
|||
id1 := UniqueId()
|
||||
time.Sleep(time.Millisecond)
|
||||
id2 := UniqueId()
|
||||
timestamp1, _ := split(strings.TrimPrefix(id1, prefix))
|
||||
timestamp2, _ := split(strings.TrimPrefix(id2, prefix))
|
||||
timestamp1, _ := split(strings.TrimPrefix(id1, UniqueIdPrefix))
|
||||
timestamp2, _ := split(strings.TrimPrefix(id2, UniqueIdPrefix))
|
||||
|
||||
if timestamp1 == timestamp2 {
|
||||
t.Fatalf("Timestamp part should update at least once a millisecond %s %s",
|
||||
|
|
Loading…
Reference in New Issue