Với mục đích thử nghiệm, tôi muốn giả lập Cloud Storage vì nó làm chậm quá trình kiểm tra.Có trình giả lập Google Cloud Storage không?
Có trình giả lập Google Cloud Storage không?
Với mục đích thử nghiệm, tôi muốn giả lập Cloud Storage vì nó làm chậm quá trình kiểm tra.Có trình giả lập Google Cloud Storage không?
Có trình giả lập Google Cloud Storage không?
Không có trình mô phỏng chính thức do Google cung cấp trong thời gian này.
Hiện tôi đang sử dụng dự án Minio (https://www.minio.io/) để xử lý hành vi của Google Storage (Minio sử dụng hệ thống tệp làm phụ trợ lưu trữ và cung cấp khả năng tương thích với S3 apiV2, tương thích với Google Storage).
Google có in-memory emulator bạn có thể sử dụng (phần lớn các chức năng chính được triển khai).
Bạn cần com.google.cloud:google-cloud-nio
trên đường dẫn thử nghiệm của mình (:0.25.0-alpha
hiện tại). Sau đó, bạn có thể sử dụng/tiêm giao diện Storage
được thực hiện bởi dịch vụ hỗ trợ kiểm tra trong bộ nhớ LocalStorageHelper
trong bộ nhớ.
Ví dụ sử dụng:
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)
);
}