mirror of
https://github.com/google/uuid.git
synced 2024-11-24 08:32:23 +02:00
use strings.NewReader() instead of math/rand.Rand
This commit is contained in:
parent
dc0f88720f
commit
e23e7efa9b
@ -1,17 +1,19 @@
|
||||
package uuid
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
"strings"
|
||||
|
||||
regen "github.com/zach-klippenstein/goregen"
|
||||
)
|
||||
|
||||
func TestUuidSources(t *testing.T) {
|
||||
|
||||
myString, _ := regen.Generate("[a-zA-Z]{1000}")
|
||||
|
||||
// Two identical sources, should give same sequence
|
||||
currentTime := time.Now().UnixNano()
|
||||
uuidSourceA := NewSource(rand.New(rand.NewSource(currentTime)))
|
||||
uuidSourceB := NewSource(rand.New(rand.NewSource(currentTime)))
|
||||
uuidSourceA := NewSource(strings.NewReader(myString))
|
||||
uuidSourceB := NewSource(strings.NewReader(myString))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
uuid1 := uuidSourceA.New()
|
||||
@ -34,8 +36,8 @@ func TestUuidSources(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set rander to rand source with same seed, should give same sequence
|
||||
uuidSourceA.SetRand(rand.New(rand.NewSource(123)))
|
||||
uuidSourceB.SetRand(rand.New(rand.NewSource(123)))
|
||||
uuidSourceA.SetRand(strings.NewReader(myString))
|
||||
uuidSourceB.SetRand(strings.NewReader(myString))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
uuid1 := uuidSourceA.New()
|
||||
@ -46,8 +48,8 @@ func TestUuidSources(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set rander to rand source with different seeds, should not give same sequence
|
||||
uuidSourceA.SetRand(rand.New(rand.NewSource(456)))
|
||||
uuidSourceB.SetRand(rand.New(rand.NewSource(789)))
|
||||
uuidSourceA.SetRand(strings.NewReader("456" + myString))
|
||||
uuidSourceB.SetRand(strings.NewReader("myString" + myString))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
uuid1 := uuidSourceA.New()
|
||||
|
@ -13,8 +13,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type test struct {
|
||||
@ -482,11 +480,13 @@ func TestBadRand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetRand(t *testing.T) {
|
||||
SetRand(rand.New(rand.NewSource(456)))
|
||||
myString := "805-9dd6-1a877cb526c678e71d38-7122-44c0-9b7c-04e7001cc78783ac3e82-47a3-4cc3-9951-13f3339d88088f5d685a-11f7-4078-ada9-de44ad2daeb7"
|
||||
|
||||
SetRand(strings.NewReader(myString))
|
||||
uuid1 := New()
|
||||
uuid2 := New()
|
||||
|
||||
SetRand(rand.New(rand.NewSource(456)))
|
||||
SetRand(strings.NewReader(myString))
|
||||
uuid3 := New()
|
||||
uuid4 := New()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user