Is there Google Cloud Storage emulator? [closed]

假如想象 提交于 2019-12-03 02:32:09

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).

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)
    );
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!