(t *testing.T)
| 132 | } |
| 133 | |
| 134 | func TestSearchPagination(t *testing.T) { |
| 135 | ctx := context.Background() |
| 136 | s := NewStore(filepath.Join(t.TempDir(), "cam.db")) |
| 137 | s.Init(ctx) |
| 138 | // Insert 5 items. |
| 139 | for i := range 5 { |
| 140 | s.UpsertItem(ctx, Item{Kind: "skill", Name: fmt.Sprintf("page-skill-%d", i), InstallKey: fmt.Sprintf("a/b:page-%d", i)}) |
| 141 | } |
| 142 | |
| 143 | // Page 1: limit 2, offset 0 → 2 items. |
| 144 | page1, _ := s.Search(ctx, SearchQuery{Query: "page-skill", Kind: "skill", Limit: 2, Offset: 0}) |
| 145 | if len(page1) != 2 { |
| 146 | t.Fatalf("page1 expected 2 items, got %d", len(page1)) |
| 147 | } |
| 148 | |
| 149 | // Page 3: limit 2, offset 4 → 1 item (the last). |
| 150 | page3, _ := s.Search(ctx, SearchQuery{Query: "page-skill", Kind: "skill", Limit: 2, Offset: 4}) |
| 151 | if len(page3) != 1 { |
| 152 | t.Fatalf("page3 expected 1 item, got %d", len(page3)) |
| 153 | } |
| 154 | |
| 155 | // Count should be 5. |
| 156 | count, _ := s.Count(ctx, SearchQuery{Query: "page-skill", Kind: "skill"}) |
| 157 | if count != 5 { |
| 158 | t.Fatalf("count expected 5, got %d", count) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // upsertSkill is a small helper for the dedup tests below. |
| 163 | func upsertSkill(t *testing.T, ctx context.Context, s *Store, name, owner, repo, installKey string) { |
nothing calls this directly
no test coverage detected