Files
seaweedfs/weed/operation/delete_content_test.go
T
35caf2542c operation: report a delete result for volumes the lookup cannot locate (#12488)
* weed/filer: retry deletes when volume replicas are offline or missing

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* operation: assert one delete result per file id in the no-location test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:38:30 -08:00

63 lines
1.8 KiB
Go

package operation
import (
"context"
"net/http"
"testing"
)
func TestDeleteFileIdsWithLookupVolumeId_NoActiveLocations(t *testing.T) {
fileIds := []string{"3,01010101", "3,02020202"}
lookupFunc := func(vids []string) (map[string]*LookupResult, error) {
results := make(map[string]*LookupResult)
for _, vid := range vids {
results[vid] = &LookupResult{
VolumeOrFileId: vid,
Locations: nil,
}
}
return results, nil
}
results := DeleteFileIdsWithLookupVolumeId(context.Background(), nil, fileIds, false, lookupFunc)
if len(results) != len(fileIds) {
t.Fatalf("expected %d results, got %d", len(fileIds), len(results))
}
counts := make(map[string]int)
for _, res := range results {
counts[res.FileId]++
if res.Status != http.StatusNotFound {
t.Errorf("expected status %d, got %d", http.StatusNotFound, res.Status)
}
if res.Error != "lookup error: volume 3 has no active locations" {
t.Errorf("unexpected error message: %q", res.Error)
}
}
for _, fileId := range fileIds {
if counts[fileId] != 1 {
t.Errorf("expected one result for %s, got %d", fileId, counts[fileId])
}
}
}
func TestDeleteFileIdsWithLookupVolumeId_MissingVolumeInLookup(t *testing.T) {
fileIds := []string{"5,01010101"}
lookupFunc := func(vids []string) (map[string]*LookupResult, error) {
// Return empty map to simulate missing volume in lookup response
return make(map[string]*LookupResult), nil
}
results := DeleteFileIdsWithLookupVolumeId(context.Background(), nil, fileIds, false, lookupFunc)
if len(results) != 1 {
t.Fatalf("expected 1 result, got %d", len(results))
}
if results[0].Status != http.StatusNotFound {
t.Errorf("expected status %d, got %d", http.StatusNotFound, results[0].Status)
}
if results[0].Error != "lookup error: volume 5 not found" {
t.Errorf("unexpected error message: %q", results[0].Error)
}
}