| 7 | ) |
| 8 | |
| 9 | func TestSequence(t *testing.T) { |
| 10 | seq := Sequence{Seed: New()} |
| 11 | |
| 12 | if min, max := seq.Bounds(); min == max { |
| 13 | t.Error("min and max of KSUID range must differ when no ids have been generated") |
| 14 | } |
| 15 | |
| 16 | for i := 0; i <= math.MaxUint16; i++ { |
| 17 | id, err := seq.Next() |
| 18 | if err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | if j := int(binary.BigEndian.Uint16(id[len(id)-2:])); j != i { |
| 22 | t.Fatalf("expected %d but got %d in %s", i, j, id) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | if _, err := seq.Next(); err == nil { |
| 27 | t.Fatal("no error returned after exhausting the id generator") |
| 28 | } |
| 29 | |
| 30 | if min, max := seq.Bounds(); min != max { |
| 31 | t.Error("after all KSUIDs were generated the min and max must be equal") |
| 32 | } |
| 33 | } |