How to mock Amazon S3 in an integration test

匿名 (未验证) 提交于 2019-12-03 08:35:02

问题:

I'm trying to get an "walking skeleton" of my app up that will use S3 for persistence. I would like to use a fake S3 service so each developer's desktop can read/write at will.

I thought mocks3 would be perfect, as I could get a jetty server up in my jUnit tests. The problem is that mocks3 doesn't allow any writes. Not even to set it up as far as I can tell.

So how do others do this?

回答1:

Tornado, a python web framework, has an example app that is just what you're looking for.

https://github.com/facebook/tornado/blob/master/demos/s3server/s3server.py

It can be used out of the box.



回答2:

There is also an s3mock tool written exactly for this purpose. It mocks the essential parts of AWS S3 API on top of local filesystem:

S3Mock api = S3Mock.create(8001, "/tmp/s3"); api.start();  AmazonS3Client client = new AmazonS3Client(new AnonymousAWSCredentials()); // use local API mock, not the AWS one client.setEndpoint("http://127.0.0.1:8001"); client.createBucket("testbucket"); client.putObject("testbucket", "file/name", "contents"); 

It's also easily embeddable and configuration-less.



回答3:

Another option is S3 ninja - emulates the S3 API for development and testing purposes.



回答4:

You can use scality s3server, in can run on your machine either using node.js or via docker and it gives you a local S3 service instance. It's open source under a BSD license github.com/scality/s3



回答5:

One option is to scrap the jetty server and use Apache VFS and the S3 plugin. With that, you can use the memory or file-based storage implementations for the integration testing.



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