mirror of https://github.com/pulumi/pulumi.git
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package resource
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewUniqueHex(t *testing.T) {
|
|
prefix := "prefix"
|
|
randlen := 8
|
|
maxlen := 100
|
|
id, err := NewUniqueHex(prefix, randlen, maxlen)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, len(prefix)+randlen, len(id))
|
|
assert.Equal(t, true, strings.HasPrefix(id, prefix))
|
|
}
|
|
|
|
func TestNewUniqueHexMaxLen2(t *testing.T) {
|
|
prefix := "prefix"
|
|
randlen := 8
|
|
maxlen := 13
|
|
_, err := NewUniqueHex(prefix, randlen, maxlen)
|
|
assert.NotNil(t, err)
|
|
}
|
|
|
|
func TestNewUniqueHexEnsureRandomness2(t *testing.T) {
|
|
prefix := "prefix"
|
|
// Just enough space to have 8 chars of randomenss
|
|
randlen := 8
|
|
maxlen := 14
|
|
id, err := NewUniqueHex(prefix, randlen, maxlen)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, maxlen, len(id))
|
|
assert.Equal(t, true, strings.HasPrefix(id, prefix))
|
|
}
|
|
|
|
func TestNewUniqueDefaults(t *testing.T) {
|
|
prefix := "prefix"
|
|
id, err := NewUniqueHex(prefix, -1, -1)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, len(prefix)+8, len(id))
|
|
assert.Equal(t, true, strings.HasPrefix(id, prefix))
|
|
}
|
|
|
|
func TestNewUniqueHexID(t *testing.T) {
|
|
prefix := "prefix"
|
|
randlen := 8
|
|
maxlen := 100
|
|
id, err := NewUniqueHexID(prefix, randlen, maxlen)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, len(prefix)+8, len(id))
|
|
assert.Equal(t, true, strings.HasPrefix(string(id), prefix))
|
|
}
|
|
|
|
func TestNewUniqueHexMaxLenID(t *testing.T) {
|
|
prefix := "prefix"
|
|
randlen := 8
|
|
maxlen := 20
|
|
id, err := NewUniqueHexID(prefix, randlen, maxlen)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, len(prefix)+8, len(id))
|
|
assert.Equal(t, true, strings.HasPrefix(string(id), prefix))
|
|
}
|
|
|
|
func TestNewUniqueDefaultsID(t *testing.T) {
|
|
prefix := "prefix"
|
|
id, err := NewUniqueHexID(prefix, -1, -1)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, len(prefix)+8, len(id))
|
|
assert.Equal(t, true, strings.HasPrefix(string(id), prefix))
|
|
}
|