MCPcopy
hub / github.com/segmentio/ksuid / TestSequence

Function TestSequence

sequence_test.go:9–33  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func 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}

Callers

nothing calls this directly

Calls 3

BoundsMethod · 0.95
NextMethod · 0.95
NewFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…