mirror of
https://github.com/google/uuid.git
synced 2025-02-20 12:33:21 +02:00
chore(tests): add strict monotonicity test case for uuid v7. (#154)
* TestVersion7MonotonicityStrict * reset timeNow and rand
This commit is contained in:
parent
016b199544
commit
16939dafc3
32
uuid_test.go
32
uuid_test.go
@ -896,3 +896,35 @@ func TestVersion7Monotonicity(t *testing.T) {
|
||||
u1 = u2
|
||||
}
|
||||
}
|
||||
|
||||
type fakeRand struct{}
|
||||
|
||||
func (g fakeRand) Read(bs []byte) (int, error) {
|
||||
for i, _ := range bs {
|
||||
bs[i] = 0x88
|
||||
}
|
||||
return len(bs), nil
|
||||
}
|
||||
|
||||
func TestVersion7MonotonicityStrict(t *testing.T) {
|
||||
timeNow = func() time.Time {
|
||||
return time.Date(2008, 8, 8, 8, 8, 8, 8, time.UTC)
|
||||
}
|
||||
defer func() {
|
||||
timeNow = time.Now
|
||||
}()
|
||||
|
||||
SetRand(fakeRand{})
|
||||
defer SetRand(nil)
|
||||
|
||||
length := 100000 // > 3906
|
||||
u1 := Must(NewV7()).String()
|
||||
for i := 0; i < length; i++ {
|
||||
u2 := Must(NewV7()).String()
|
||||
if u2 <= u1 {
|
||||
t.Errorf("monotonicity failed at #%d: %s(next) < %s(before)", i, u2, u1)
|
||||
break
|
||||
}
|
||||
u1 = u2
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user