feat(store): add TaskStore CRUD and batch query methods for files and blobs
This commit is contained in:
@@ -230,6 +230,84 @@ func TestFileStore_GetBlobSHA256ByID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileStore_GetByIDs(t *testing.T) {
|
||||
db := setupFileTestDB(t)
|
||||
store := NewFileStore(db)
|
||||
ctx := context.Background()
|
||||
|
||||
store.Create(ctx, &model.File{Name: "a.bin", BlobSHA256: "h1"})
|
||||
store.Create(ctx, &model.File{Name: "b.bin", BlobSHA256: "h2"})
|
||||
store.Create(ctx, &model.File{Name: "c.bin", BlobSHA256: "h3"})
|
||||
|
||||
files, err := store.GetByIDs(ctx, []int64{1, 3})
|
||||
if err != nil {
|
||||
t.Fatalf("GetByIDs() error = %v", err)
|
||||
}
|
||||
if len(files) != 2 {
|
||||
t.Fatalf("len(files) = %d, want 2", len(files))
|
||||
}
|
||||
names := map[string]bool{}
|
||||
for _, f := range files {
|
||||
names[f.Name] = true
|
||||
}
|
||||
if !names["a.bin"] || !names["c.bin"] {
|
||||
t.Errorf("expected a.bin and c.bin, got %v", files)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileStore_GetByIDs_Empty(t *testing.T) {
|
||||
db := setupFileTestDB(t)
|
||||
store := NewFileStore(db)
|
||||
ctx := context.Background()
|
||||
|
||||
files, err := store.GetByIDs(ctx, []int64{})
|
||||
if err != nil {
|
||||
t.Fatalf("GetByIDs() error = %v", err)
|
||||
}
|
||||
if len(files) != 0 {
|
||||
t.Errorf("len(files) = %d, want 0", len(files))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileStore_GetByIDs_NotFound(t *testing.T) {
|
||||
db := setupFileTestDB(t)
|
||||
store := NewFileStore(db)
|
||||
ctx := context.Background()
|
||||
|
||||
files, err := store.GetByIDs(ctx, []int64{999})
|
||||
if err != nil {
|
||||
t.Fatalf("GetByIDs() error = %v", err)
|
||||
}
|
||||
if len(files) != 0 {
|
||||
t.Errorf("len(files) = %d, want 0 for non-existent IDs", len(files))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileStore_GetByIDs_SoftDeleteExcluded(t *testing.T) {
|
||||
db := setupFileTestDB(t)
|
||||
store := NewFileStore(db)
|
||||
ctx := context.Background()
|
||||
|
||||
store.Create(ctx, &model.File{Name: "a.bin", BlobSHA256: "h1"})
|
||||
store.Create(ctx, &model.File{Name: "b.bin", BlobSHA256: "h2"})
|
||||
store.Create(ctx, &model.File{Name: "c.bin", BlobSHA256: "h3"})
|
||||
|
||||
store.Delete(ctx, 2)
|
||||
|
||||
files, err := store.GetByIDs(ctx, []int64{1, 2, 3})
|
||||
if err != nil {
|
||||
t.Fatalf("GetByIDs() error = %v", err)
|
||||
}
|
||||
if len(files) != 2 {
|
||||
t.Fatalf("len(files) = %d, want 2 (soft-deleted excluded)", len(files))
|
||||
}
|
||||
for _, f := range files {
|
||||
if f.ID == 2 {
|
||||
t.Error("soft-deleted file ID 2 should not appear")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileStore_GetBlobSHA256ByID_NotFound(t *testing.T) {
|
||||
db := setupFileTestDB(t)
|
||||
store := NewFileStore(db)
|
||||
|
||||
Reference in New Issue
Block a user