From 0631d57f392759dd399e3a958f063cbc657ac484 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Tue, 29 Aug 2023 10:25:52 +0400 Subject: [PATCH] tests: Fix panic, if object not found Signed-off-by: Evgenii Baidakov --- downloader/download.go | 15 ++++++++++----- integration_test.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/downloader/download.go b/downloader/download.go index e1939cb..32a6dcc 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -358,14 +358,19 @@ func (d *Downloader) byAttribute(c *fasthttp.RequestCtx, f func(request, *pool.P if n == 0 { err = res.Close() - if errors.Is(err, io.EOF) { - log.Error("object not found", zap.Error(err)) - response.Error(c, "object not found", fasthttp.StatusNotFound) + if err != nil { + if errors.Is(err, io.EOF) { + log.Error("object not found", zap.Error(err)) + response.Error(c, "object not found", fasthttp.StatusNotFound) + return + } + + log.Error("read object list failed", zap.Error(err)) + response.Error(c, "read object list failed: "+err.Error(), fasthttp.StatusBadRequest) return } - log.Error("read object list failed", zap.Error(err)) - response.Error(c, "read object list failed: "+err.Error(), fasthttp.StatusBadRequest) + response.Error(c, "Not Found", fasthttp.StatusNotFound) return } diff --git a/integration_test.go b/integration_test.go index 73b6629..4d9c6a8 100644 --- a/integration_test.go +++ b/integration_test.go @@ -83,6 +83,7 @@ func TestIntegration(t *testing.T) { t.Run("put with duplicate keys "+image, func(t *testing.T) { putWithDuplicateKeys(t, CID) }) t.Run("simple get "+image, func(t *testing.T) { simpleGet(ctx, t, clientPool, ownerID, CID, signer) }) t.Run("get by attribute "+image, func(t *testing.T) { getByAttr(ctx, t, clientPool, ownerID, CID, signer) }) + t.Run("get by attribute, not found "+image, func(t *testing.T) { getByAttrNotFound(t) }) t.Run("get zip "+image, func(t *testing.T) { getZip(ctx, t, clientPool, ownerID, CID, signer) }) cancel() @@ -273,6 +274,15 @@ func getByAttr(ctx context.Context, t *testing.T, clientPool *pool.Pool, ownerID checkGetByAttrResponse(t, resp, content, expectedAttr) } +func getByAttrNotFound(t *testing.T) { + keyAttr, valAttr := "some-attr-no", "some-get-by-attr-value-no" + + resp, err := http.Get(testHost + "/get_by_attribute/" + testContainerName + "/" + keyAttr + "/" + valAttr) + + require.Equal(t, http.StatusNotFound, resp.StatusCode) + require.NoError(t, err) +} + func getZip(ctx context.Context, t *testing.T, clientPool *pool.Pool, ownerID user.ID, CID cid.ID, signer user.Signer) { names := []string{"zipfolder/dir/name1.txt", "zipfolder/name2.txt"} contents := []string{"content of file1", "content of file2"}