(t *testing.T)
| 11 | const testSecret = "0123456789abcdef0123456789abcdef" |
| 12 | |
| 13 | func TestCursorRoundTrip(t *testing.T) { |
| 14 | type cur struct { |
| 15 | After string `json:"after"` |
| 16 | Dir string `json:"dir"` |
| 17 | } |
| 18 | in := cur{After: "msg_123", Dir: "inbound"} |
| 19 | enc, err := EncodeCursor(testSecret, in) |
| 20 | if err != nil { |
| 21 | t.Fatalf("encode: %v", err) |
| 22 | } |
| 23 | if enc == "" { |
| 24 | t.Fatal("expected non-empty cursor") |
| 25 | } |
| 26 | // The signed cursor is payload + "." + signature. |
| 27 | if strings.Count(enc, ".") != 1 { |
| 28 | t.Fatalf("expected exactly one '.' separator, got %q", enc) |
| 29 | } |
| 30 | var out cur |
| 31 | if err := DecodeCursor([]string{testSecret}, enc, &out); err != nil { |
| 32 | t.Fatalf("decode: %v", err) |
| 33 | } |
| 34 | if out != in { |
| 35 | t.Fatalf("round-trip mismatch: got %+v want %+v", out, in) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestDecodeCursorEmptyIsNoop(t *testing.T) { |
| 40 | out := struct{ A string }{A: "untouched"} |
nothing calls this directly
no test coverage detected