summaryrefslogtreecommitdiff
path: root/internal/controlplane/usage_test.go
blob: d47ce1609715c4c1ed85a113c8a14393f4ad92e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package controlplane

import (
	"errors"
	"testing"
	"time"
)

func TestUsageCursorRoundTrip(t *testing.T) {
	record := UsageRecord{RequestID: "req_cursor_test", StartedAt: time.Date(2026, 8, 6, 2, 3, 4, 567, time.UTC)}
	cursor, err := decodeUsageCursor(encodeUsageCursor(record))
	if err != nil {
		t.Fatal(err)
	}
	if cursor.RequestID != record.RequestID || !cursor.StartedAt.Equal(record.StartedAt) {
		t.Fatalf("cursor = %+v, want request %s at %v", cursor, record.RequestID, record.StartedAt)
	}
}

func TestUsageCursorRejectsInvalidInput(t *testing.T) {
	for _, raw := range []string{"not-base64!", "e30", string(make([]byte, 2049))} {
		if _, err := decodeUsageCursor(raw); !errors.Is(err, ErrInvalidUsageCursor) {
			t.Fatalf("decodeUsageCursor(%q) error = %v", raw, err)
		}
	}
}