Is there a Google Cloud Storage emulator?

For testing, I would like to make fun of cloud storage because it slows down the tests.

Is there a Google Cloud Storage emulator?

+6
source share
3 answers

There is currently no official emulator provided by Google.

I am currently using the Minio project ( https://www.minio.io/ ) for the mocking behavior of Google Storage in development (Minio uses the file system as storage and provides compatibility with S3 apiV2 compatible with Google Storage).

+5
source

Google has an in-memory emulator that you can use (most of the basic functions are implemented).

You need com.google.cloud:google-cloud-nio in your test path ( :0.25.0-alpha currently). Then you can use / implement the Storage interface implemented in the LocalStorageHelper test helper LocalStorageHelper .

Usage example:

  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) ); } 
+7
source

It looks like there is now a datastore emulator available in beta.

Installation instructions for Linux / Windows can be found here.

For Linux, they can be summarized as follows:

  • Installation requires Java JRE 7+.
  • Then the emulator is installed using the command:
    gcloud components install cloud-datastore-emulator
  • After installation, run the emulator by running:
    gcloud beta emulators datastore start
  • When starting the emulator, configure some environment variables that the tel application uses to use the emulated data store: (gcloud beta emulators datastore env-init)
  • Now run the application as usual, and it should use an emulated data warehouse.
-one
source

All Articles