| 304 | } |
| 305 | |
| 306 | func TestVersion1(t *testing.T) { |
| 307 | uuid1, err := NewUUID() |
| 308 | if err != nil { |
| 309 | t.Fatalf("could not create UUID: %v", err) |
| 310 | } |
| 311 | uuid2, err := NewUUID() |
| 312 | if err != nil { |
| 313 | t.Fatalf("could not create UUID: %v", err) |
| 314 | } |
| 315 | |
| 316 | if uuid1 == uuid2 { |
| 317 | t.Errorf("%s:duplicate uuid", uuid1) |
| 318 | } |
| 319 | if v := uuid1.Version(); v != 1 { |
| 320 | t.Errorf("%s: version %s expected 1", uuid1, v) |
| 321 | } |
| 322 | if v := uuid2.Version(); v != 1 { |
| 323 | t.Errorf("%s: version %s expected 1", uuid2, v) |
| 324 | } |
| 325 | n1 := uuid1.NodeID() |
| 326 | n2 := uuid2.NodeID() |
| 327 | if !bytes.Equal(n1, n2) { |
| 328 | t.Errorf("Different nodes %x != %x", n1, n2) |
| 329 | } |
| 330 | t1 := uuid1.Time() |
| 331 | t2 := uuid2.Time() |
| 332 | q1 := uuid1.ClockSequence() |
| 333 | q2 := uuid2.ClockSequence() |
| 334 | |
| 335 | switch { |
| 336 | case t1 == t2 && q1 == q2: |
| 337 | t.Error("time stopped") |
| 338 | case t1 > t2 && q1 == q2: |
| 339 | t.Error("time reversed") |
| 340 | case t1 < t2 && q1 != q2: |
| 341 | t.Error("clock sequence changed unexpectedly") |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | func TestNode(t *testing.T) { |
| 346 | // This test is mostly to make sure we don't leave nodeMu locked. |