Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Google Cloud Storage emulator? [closed]

Tags:

For the purpose of testing, I would like to mock Cloud Storage because it slows tests down.

Is there Google Cloud Storage emulator?

like image 850
Evgeny Timoshenko Avatar asked May 31 '16 09:05

Evgeny Timoshenko


People also ask

Is Google Cloud coming to an end?

December 31, 2020 will be the last day Google Cloud Print is supported. On January 1, 2021 users will no longer be able to print using GCP. With improvements to native Chrome OS printing and enhanced feature sets of comparable solutions, Google choose to end support for GCP.

Is there a limit to Google Cloud Storage?

There is a default bandwidth quota for each region that has data egress from Cloud Storage to Google services. This quota is 200 Gbps per project.

Can you buy Google Cloud Storage?

Your Google Account starts with 15 GB of included cloud storage to use across Google Drive, Gmail, and Google Photos. You can buy more storage within Google Drive, or upgrade to Google One, to get extra benefits. Note: If you have a work or school account, you can't buy more storage for yourself.


2 Answers

Google has an in-memory emulator you can use (majority of core functions are implemented).

You need com.google.cloud:google-cloud-nio on your test classpath (:0.25.0-alpha currently). Then you can use/inject Storage interface implemented by the in-memory LocalStorageHelper test-helper service.

Example usage:

  import com.google.cloud.storage.Storage;   import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;    @Test   public void exampleInMemoryGoogleStorageTest() {     Storage storage = LocalStorageHelper.getOptions().getService();      final String blobPath = "test/path/foo.txt";     final String testBucketName = "test-bucket";     BlobInfo blobInfo = BlobInfo.newBuilder(         BlobId.of(testBucketName, blobPath)     ).build();      storage.create(blobInfo, "randomContent".getBytes(StandardCharsets.UTF_8));     Iterable<Blob> allBlobsIter = storage.list(testBucketName).getValues();     // expect to find the blob we saved when iterating over bucket blobs     assertTrue(         StreamSupport.stream(allBlobsIter.spliterator(), false)             .map(BlobInfo::getName)             .anyMatch(blobPath::equals)     );   } 
like image 102
ThomasMH Avatar answered Sep 20 '22 19:09

ThomasMH


There isn't an official emulator provided by Google for the time being.

I'm currently using project Minio (https://www.minio.io/) for mocking Google Storage's behavior in development (Minio uses the filesystem as storage backend and provides compatibility with S3 apiV2, which is compatible with Google Storage).

like image 30
Caio Tomazelli Avatar answered Sep 23 '22 19:09

Caio Tomazelli