package applog import ( "testing" "time" ) func TestCursorRoundTripAndOrder(t *testing.T) { r := Record{TS: time.Date(2026, 8, 10, 12, 0, 30, 500, time.UTC), Box: "b1", Seq: 42, Msg: "m"} c, ok := DecodeCursor(EncodeCursor(r)) if !ok || !c.TS.Equal(r.TS) || c.Box != "b1" || c.Seq != 42 { t.Fatalf("round trip: %+v %v", c, ok) } // Before mirrors MergeRecords' (ts, box, seq) order exactly. if c.Before(r) { t.Fatal("a cursor at r is not before r") } for _, after := range []Record{ {TS: r.TS.Add(time.Nanosecond), Box: "a0", Seq: 1}, {TS: r.TS, Box: "b2", Seq: 1}, {TS: r.TS, Box: "b1", Seq: 43}, } { if !c.Before(after) { t.Fatalf("cursor should be before %+v", after) } } if c.Before(Record{TS: r.TS, Box: "b1", Seq: 41}) { t.Fatal("cursor before an earlier seq") } for _, bad := range []string{"", "!!!", "bm90IGpzb24"} { if _, ok := DecodeCursor(bad); ok { t.Errorf("DecodeCursor(%q) ok", bad) } } }