fsouza / fake-gcs-server

Google Cloud Storage emulator & testing library.
https://pkg.go.dev/github.com/fsouza/fake-gcs-server/fakestorage?tab=doc
BSD 2-Clause "Simplified" License
1.06k stars 209 forks source link

Batched commands don't work #411

Open oittaa opened 3 years ago

oittaa commented 3 years ago

For example you can't delete multiple blobs in a batch like you can with the actual the Google service. Test case below.

import tempfile
from google.auth.credentials import AnonymousCredentials
from google.cloud import storage, exceptions

client = storage.Client(
    credentials=AnonymousCredentials(),
    project="test",
)
bucket = client.get_bucket("test-bucket")
blob = bucket.blob("key1")
blob.upload_from_string("test1")
blob = bucket.blob("key2")
blob.upload_from_string("test2")
try:
    with client.batch():
        bucket.delete_blob("key1")
        bucket.delete_blob("key2")
except exceptions.NotFound:
    pass

# List the Buckets
for bucket in client.list_buckets():
    print(f"Bucket: {bucket.name}\n")

    # List the Blobs in each Bucket
    for blob in bucket.list_blobs():
        print(f"Blob: {blob.name}")

        # Print the content of the Blob
        b = bucket.get_blob(blob.name)
        with tempfile.NamedTemporaryFile() as temp_file:
            s = b.download_to_filename(temp_file.name)
            temp_file.seek(0, 0)
            print(temp_file.read(), "\n")

Output:

Bucket: test-bucket

Blob: key1
b'test1'

Blob: key2
b'test2'

The expected result is an empty bucket.

fsouza commented 3 years ago

Indeed batch requests aren't supported currently. Marking as help wanted in case someone wants to contribute.

Relevant docs: https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch