[GH-ISSUE #722] Size is not correctly returned after upload #122

Closed
opened 2026-03-03 12:08:30 +03:00 by kerem · 2 comments
Owner

Originally created by @drigz on GitHub (Mar 18, 2022).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/722

I'm using the returned size to double-check the upload as we found some of our uploads were truncated and are trying to work out why. This works with GCS but breaks our tests. You can also see this by adding an additional assertion to upload_test.go:

$ git diff
diff --git a/fakestorage/upload_test.go b/fakestorage/upload_test.go
index 6a9650e..d6bd30e 100644
--- a/fakestorage/upload_test.go
+++ b/fakestorage/upload_test.go
@@ -82,6 +82,9 @@ func TestServerClientObjectWriter(t *testing.T) {
                                                n, baseContent)
                                }
 
+                               if returnedSize := w.Attrs().Size; returnedSize != int64(len(content)) {
+                                       t.Errorf("wrong writer.Attrs() size returned\nwant %d\ngot  %d", len(content), returnedSize)
+                               }
                                if returnedChecksum := w.Attrs().CRC32C; returnedChecksum != u32Checksum {
                                        t.Errorf("wrong writer.Attrs() checksum returned\nwant %d\ngot  %d", u32Checksum, returnedChecksum)
                                }
$ go test github.com/fsouza/fake-gcs-server/fakestorage
--- FAIL: TestServerClientObjectWriter (0.02s)
    --- FAIL: TestServerClientObjectWriter/http_listener (0.24s)
        --- FAIL: TestServerClientObjectWriter/http_listener/default_chunk_size (0.07s)
            upload_test.go:86: wrong writer.Attrs() size returned
                want 4718592
                got  0
        --- FAIL: TestServerClientObjectWriter/http_listener/small_chunk_size (0.17s)
            upload_test.go:86: wrong writer.Attrs() size returned
                want 4718592
                got  0
    --- FAIL: TestServerClientObjectWriter/https_listener (0.25s)
        --- FAIL: TestServerClientObjectWriter/https_listener/default_chunk_size (0.08s)
            upload_test.go:86: wrong writer.Attrs() size returned
                want 4718592
                got  0
        --- FAIL: TestServerClientObjectWriter/https_listener/small_chunk_size (0.16s)
            upload_test.go:86: wrong writer.Attrs() size returned
                want 4718592
                got  0
    --- FAIL: TestServerClientObjectWriter/no_listener (0.25s)
        --- FAIL: TestServerClientObjectWriter/no_listener/default_chunk_size (0.08s)
            upload_test.go:86: wrong writer.Attrs() size returned
                want 4718592
                got  0
        --- FAIL: TestServerClientObjectWriter/no_listener/small_chunk_size (0.16s)
            upload_test.go:86: wrong writer.Attrs() size returned
                want 4718592
                got  0
FAIL
FAIL    github.com/fsouza/fake-gcs-server/fakestorage   0.806s
FAIL

I looked at sending a PR, but while it seems obvious how to set for most cases where ObjectAttrs{} is created when Content is already available, it wasn't obvious how to set it for a resumable upload.

Originally created by @drigz on GitHub (Mar 18, 2022). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/722 I'm using the returned size to double-check the upload as we found some of our uploads were truncated and are trying to work out why. This works with GCS but breaks our tests. You can also see this by adding an additional assertion to upload_test.go: ``` $ git diff diff --git a/fakestorage/upload_test.go b/fakestorage/upload_test.go index 6a9650e..d6bd30e 100644 --- a/fakestorage/upload_test.go +++ b/fakestorage/upload_test.go @@ -82,6 +82,9 @@ func TestServerClientObjectWriter(t *testing.T) { n, baseContent) } + if returnedSize := w.Attrs().Size; returnedSize != int64(len(content)) { + t.Errorf("wrong writer.Attrs() size returned\nwant %d\ngot %d", len(content), returnedSize) + } if returnedChecksum := w.Attrs().CRC32C; returnedChecksum != u32Checksum { t.Errorf("wrong writer.Attrs() checksum returned\nwant %d\ngot %d", u32Checksum, returnedChecksum) } $ go test github.com/fsouza/fake-gcs-server/fakestorage --- FAIL: TestServerClientObjectWriter (0.02s) --- FAIL: TestServerClientObjectWriter/http_listener (0.24s) --- FAIL: TestServerClientObjectWriter/http_listener/default_chunk_size (0.07s) upload_test.go:86: wrong writer.Attrs() size returned want 4718592 got 0 --- FAIL: TestServerClientObjectWriter/http_listener/small_chunk_size (0.17s) upload_test.go:86: wrong writer.Attrs() size returned want 4718592 got 0 --- FAIL: TestServerClientObjectWriter/https_listener (0.25s) --- FAIL: TestServerClientObjectWriter/https_listener/default_chunk_size (0.08s) upload_test.go:86: wrong writer.Attrs() size returned want 4718592 got 0 --- FAIL: TestServerClientObjectWriter/https_listener/small_chunk_size (0.16s) upload_test.go:86: wrong writer.Attrs() size returned want 4718592 got 0 --- FAIL: TestServerClientObjectWriter/no_listener (0.25s) --- FAIL: TestServerClientObjectWriter/no_listener/default_chunk_size (0.08s) upload_test.go:86: wrong writer.Attrs() size returned want 4718592 got 0 --- FAIL: TestServerClientObjectWriter/no_listener/small_chunk_size (0.16s) upload_test.go:86: wrong writer.Attrs() size returned want 4718592 got 0 FAIL FAIL github.com/fsouza/fake-gcs-server/fakestorage 0.806s FAIL ``` I looked at sending a PR, but while it seems obvious how to set for most cases where ObjectAttrs{} is created when Content is already available, it wasn't obvious how to set it for a resumable upload.
kerem closed this issue 2026-03-03 12:08:30 +03:00
Author
Owner

@fsouza commented on GitHub (Mar 20, 2022):

Oh interesting. I'll investigate what's going on.

<!-- gh-comment-id:1073282142 --> @fsouza commented on GitHub (Mar 20, 2022): Oh interesting. I'll investigate what's going on.
Author
Owner

@fsouza commented on GitHub (Mar 20, 2022):

Thanks for providing the necessary test modification. Looks like we were incorrectly omitting that attribute, see #723. Once that's green, I'll merge it and cut a new release.

<!-- gh-comment-id:1073289903 --> @fsouza commented on GitHub (Mar 20, 2022): Thanks for providing the necessary test modification. Looks like we were incorrectly omitting that attribute, see #723. Once that's green, I'll merge it and cut a new release.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#122
No description provided.