feat(store): add TaskStore CRUD and batch query methods for files and blobs
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user