Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
tests: Fix panic, if object not found
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 29, 2023
1 parent e9877ad commit 0631d57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 10 additions & 5 deletions downloader/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Check warning on line 366 in downloader/download.go

View check run for this annotation

Codecov / codecov/patch

downloader/download.go#L361-L366

Added lines #L361 - L366 were not covered by tests

log.Error("read object list failed", zap.Error(err))
response.Error(c, "read object list failed: "+err.Error(), fasthttp.StatusBadRequest)

Check warning on line 369 in downloader/download.go

View check run for this annotation

Codecov / codecov/patch

downloader/download.go#L368-L369

Added lines #L368 - L369 were not covered by tests
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)

Check warning on line 373 in downloader/download.go

View check run for this annotation

Codecov / codecov/patch

downloader/download.go#L373

Added line #L373 was not covered by tests
return
}

Expand Down
10 changes: 10 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 0631d57

Please sign in to comment.