feat(store): add TaskStore CRUD and batch query methods for files and blobs

This commit is contained in:
dailz
2026-04-15 21:30:51 +08:00
parent d46a784efb
commit acf8c1d62b
7 changed files with 520 additions and 0 deletions

View File

@@ -133,6 +133,59 @@ func TestBlobStore_Delete(t *testing.T) {
}
}
func TestBlobStore_GetBySHA256s(t *testing.T) {
db := setupBlobTestDB(t)
store := NewBlobStore(db)
ctx := context.Background()
store.Create(ctx, &model.FileBlob{SHA256: "h1", MinioKey: "files/h1", FileSize: 100})
store.Create(ctx, &model.FileBlob{SHA256: "h2", MinioKey: "files/h2", FileSize: 200})
store.Create(ctx, &model.FileBlob{SHA256: "h3", MinioKey: "files/h3", FileSize: 300})
blobs, err := store.GetBySHA256s(ctx, []string{"h1", "h3"})
if err != nil {
t.Fatalf("GetBySHA256s() error = %v", err)
}
if len(blobs) != 2 {
t.Fatalf("len(blobs) = %d, want 2", len(blobs))
}
keys := map[string]bool{}
for _, b := range blobs {
keys[b.SHA256] = true
}
if !keys["h1"] || !keys["h3"] {
t.Errorf("expected h1 and h3, got %v", blobs)
}
}
func TestBlobStore_GetBySHA256s_Empty(t *testing.T) {
db := setupBlobTestDB(t)
store := NewBlobStore(db)
ctx := context.Background()
blobs, err := store.GetBySHA256s(ctx, []string{})
if err != nil {
t.Fatalf("GetBySHA256s() error = %v", err)
}
if len(blobs) != 0 {
t.Errorf("len(blobs) = %d, want 0", len(blobs))
}
}
func TestBlobStore_GetBySHA256s_NotFound(t *testing.T) {
db := setupBlobTestDB(t)
store := NewBlobStore(db)
ctx := context.Background()
blobs, err := store.GetBySHA256s(ctx, []string{"nonexistent"})
if err != nil {
t.Fatalf("GetBySHA256s() error = %v", err)
}
if len(blobs) != 0 {
t.Errorf("len(blobs) = %d, want 0 for non-existent SHA256s", len(blobs))
}
}
func TestBlobStore_SHA256_UniqueConstraint(t *testing.T) {
db := setupBlobTestDB(t)
store := NewBlobStore(db)