Restrict wildcard evict to <dir>/*, return 503 on lock contention, surface S3 list errors
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-04 16:06:54 +11:00
parent c1c5ff987c
commit e67629cb2d
5 changed files with 221 additions and 32 deletions
+15 -4
View File
@@ -2,6 +2,8 @@ package v2
import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
"testing"
@@ -40,9 +42,18 @@ func TestRemoteEvictDelegatesToEvictor(t *testing.T) {
}
}
func TestRemoteEvictMapsProxyErrorStatus(t *testing.T) {
ev := &fakeEvictor{err: &proxy.ProxyError{Status: http.StatusNotFound, Message: "remote not found"}}
if code := deleteObject(ev, "x"); code != http.StatusNotFound {
t.Errorf("code = %d, want 404", code)
func TestRemoteEvictMapsErrorStatus(t *testing.T) {
for name, tc := range map[string]struct {
err error
want int
}{
"bad wildcard": {&proxy.ProxyError{Status: http.StatusBadRequest, Message: "wildcard evict must be <dir>/*"}, http.StatusBadRequest},
"unknown remote": {&proxy.ProxyError{Status: http.StatusNotFound, Message: "remote not found"}, http.StatusNotFound},
"lock busy": {fmt.Errorf("wrapped: %w", &proxy.ProxyError{Status: http.StatusServiceUnavailable, Message: "retry"}), http.StatusServiceUnavailable},
"other error": {errors.New("db down"), http.StatusInternalServerError},
} {
if code := deleteObject(&fakeEvictor{err: tc.err}, "x"); code != tc.want {
t.Errorf("%s: code = %d, want %d", name, code, tc.want)
}
}
}