package common import ( "testing" "time" "github.com/google/uuid" ) func TestCursorRoundTrip(t *testing.T) { want := CursorKeyCtx{ Time: time.Date(2026, 10, 20, 12, 30, 45, 123456789, time.UTC), ID: uuid.MustParse("11111111-1111-4111-8111-111111111111"), ContextID: uuid.MustParse("22222222-2222-4222-8222-222222222222"), } encoded := EncodeCursor(want) got, ok := DecodeCursor(encoded) if !ok { t.Fatal("cursor did not decode") } if !got.Time.Equal(want.Time) || got.ID != want.ID || got.ContextID != want.ContextID { t.Fatalf("cursor round trip changed the key: %+v", got) } for _, invalid := range []string{"not-base64!", "", "aGVsbG8"} { if _, ok := DecodeCursor(invalid); ok { t.Fatalf("invalid cursor %q was accepted", invalid) } } }