| 1 | package ledger |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestValidName(t *testing.T) { |
| 6 | for _, ok := range []string{"carbon", "a", "prompt-registry", "x9"} { |
| 7 | if !ValidName(ok) { |
| 8 | t.Errorf("ValidName(%q) = false, want true", ok) |
| 9 | } |
| 10 | } |
| 11 | for _, bad := range []string{"", "Carbon", "-x", "a_b", "a/b", "café", |
| 12 | "0123456789012345678901234567890123456789012345678901234567890123x"} { |
| 13 | if ValidName(bad) { |
| 14 | t.Errorf("ValidName(%q) = true, want false", bad) |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func TestKeys(t *testing.T) { |
| 20 | if got, want := HeadKey("bab", "platform", "carbon"), |
| 21 | "ledgers/bab/platform/carbon/HEAD.json"; got != want { |
| 22 | t.Errorf("HeadKey = %q, want %q", got, want) |
| 23 | } |
| 24 | if got, want := ManifestKey("bab", "platform"), |
| 25 | "ledgers/bab/platform/ledgers.json"; got != want { |
| 26 | t.Errorf("ManifestKey = %q, want %q", got, want) |
| 27 | } |
| 28 | if got, want := BlobKey("bab", "platform", "prompts", "abc123"), |
| 29 | "ledgers/bab/platform/prompts/blobs/abc123"; got != want { |
| 30 | t.Errorf("BlobKey = %q, want %q", got, want) |
| 31 | } |
| 32 | sha := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 33 | if got, want := EntryKey("bab", "platform", "carbon", "2026-08-03T21:04:00Z", sha), |
| 34 | "ledgers/bab/platform/carbon/entries/20260803T210400Z-0123456789ab.json"; got != want { |
| 35 | t.Errorf("EntryKey = %q, want %q", got, want) |
| 36 | } |
| 37 | } |
| 38 | |