MCPcopy
hub / github.com/google/uuid / TestClockSeq

Function TestClockSeq

uuid_test.go:228–278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

226}
227
228func TestClockSeq(t *testing.T) {
229 // Fake time.Now for this test to return a monotonically advancing time; restore it at end.
230 defer func(orig func() time.Time) { timeNow = orig }(timeNow)
231 monTime := time.Now()
232 timeNow = func() time.Time {
233 monTime = monTime.Add(1 * time.Second)
234 return monTime
235 }
236
237 SetClockSequence(-1)
238 uuid1, err := NewUUID()
239 if err != nil {
240 t.Fatalf("could not create UUID: %v", err)
241 }
242 uuid2, err := NewUUID()
243 if err != nil {
244 t.Fatalf("could not create UUID: %v", err)
245 }
246
247 if s1, s2 := uuid1.ClockSequence(), uuid2.ClockSequence(); s1 != s2 {
248 t.Errorf("clock sequence %d != %d", s1, s2)
249 }
250
251 SetClockSequence(-1)
252 uuid2, err = NewUUID()
253 if err != nil {
254 t.Fatalf("could not create UUID: %v", err)
255 }
256
257 // Just on the very off chance we generated the same sequence
258 // two times we try again.
259 if uuid1.ClockSequence() == uuid2.ClockSequence() {
260 SetClockSequence(-1)
261 uuid2, err = NewUUID()
262 if err != nil {
263 t.Fatalf("could not create UUID: %v", err)
264 }
265 }
266 if s1, s2 := uuid1.ClockSequence(), uuid2.ClockSequence(); s1 == s2 {
267 t.Errorf("Duplicate clock sequence %d", s1)
268 }
269
270 SetClockSequence(0x1234)
271 uuid1, err = NewUUID()
272 if err != nil {
273 t.Fatalf("could not create UUID: %v", err)
274 }
275 if seq := uuid1.ClockSequence(); seq != 0x1234 {
276 t.Errorf("%s: expected seq 0x1234 got 0x%04x", uuid1, seq)
277 }
278}
279
280func TestCoding(t *testing.T) {
281 text := "7d444840-9dc0-11d1-b245-5ffdce74fad2"

Callers

nothing calls this directly

Calls 3

ClockSequenceMethod · 0.95
SetClockSequenceFunction · 0.85
NewUUIDFunction · 0.85

Tested by

no test coverage detected