mirror of
https://github.com/restic/rest-server.git
synced 2026-09-26 22:11:37 -07:00
return empty array if there are no objects to list
Previously "null" was returned, which does not match the REST backend specification.
This commit is contained in:
@@ -379,6 +379,30 @@ func TestResticErrorHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyList(t *testing.T) {
|
||||||
|
mux, _, _, _, cleanup := createTestHandler(t, Server{
|
||||||
|
AppendOnly: true,
|
||||||
|
NoAuth: true,
|
||||||
|
Debug: true,
|
||||||
|
})
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
// create the repo
|
||||||
|
checkRequest(t, mux.ServeHTTP,
|
||||||
|
newRequest(t, "POST", "/?create=true", nil),
|
||||||
|
[]wantFunc{wantCode(http.StatusOK)})
|
||||||
|
|
||||||
|
for i := 1; i <= 2; i++ {
|
||||||
|
req := newRequest(t, "GET", "/data/", nil)
|
||||||
|
if i == 2 {
|
||||||
|
req.Header.Set("Accept", "application/vnd.x.restic.rest.v2")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkRequest(t, mux.ServeHTTP, req,
|
||||||
|
[]wantFunc{wantCode(http.StatusOK), wantBody("[]")})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestListWithUnexpectedFiles(t *testing.T) {
|
func TestListWithUnexpectedFiles(t *testing.T) {
|
||||||
mux, _, _, tempdir, cleanup := createTestHandler(t, Server{
|
mux, _, _, tempdir, cleanup := createTestHandler(t, Server{
|
||||||
AppendOnly: true,
|
AppendOnly: true,
|
||||||
|
|||||||
+2
-2
@@ -375,7 +375,7 @@ func (h *Handler) listBlobsV1(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var names []string
|
names := []string{}
|
||||||
for _, i := range items {
|
for _, i := range items {
|
||||||
if isHashed(objectType) {
|
if isHashed(objectType) {
|
||||||
if !i.IsDir() {
|
if !i.IsDir() {
|
||||||
@@ -434,7 +434,7 @@ func (h *Handler) listBlobsV2(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var blobs []Blob
|
blobs := []Blob{}
|
||||||
for _, i := range items {
|
for _, i := range items {
|
||||||
if isHashed(objectType) {
|
if isHashed(objectType) {
|
||||||
if !i.IsDir() {
|
if !i.IsDir() {
|
||||||
|
|||||||
Reference in New Issue
Block a user