Closed llebleis closed 3 months ago
@llebleis Hello. Looking at the code you shared, I think it comes down to the way you are addressing the bucket. aws.directories.new
will create a bucket object but it won't actually persist it (to mocks or otherwise). If you change the new
to create
or else call save
on the bucket before trying to create the file I think you should have better luck.
Thanks @geemus for the quick answer. When using aws.directories.create
it works perfectly with Fog.mock!
but no more without. To make it work I added a '/' character at the end of the bucket_name and now I've got warning from Fog:
[fog][WARNING] fog: the specified s3 bucket name(bucket_name/) is not a valid dns name, which will negatively impact performance. For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/BucketRestrictions.html
But I think I can live with these warning.
Thanks then I will close that "non" issue
@llebleis - Ah, yeah in real usage you would probably create the bucket out-of-band and then just refer to it with new here (instead of creating it each time). You could make it work in both by first checking to see if the bucket exists before trying to create it, but that might be more complicated that really want (and it incurs a performance impact to check for the bucket each time).
That warning has to do with whether or not the bucket_name can be used as a subdomain (which something with /
cannot because it's not valid in that context). I don't think that the / should be needed in general. Adding it here would create a new bucket in real usage (instead of using the existing bucket, where it would error because it already exists). I'm guessing that isn't really your intention, so I would probably take that back out and delete the new bucket if you don't need it. Then you can either presume the bucket exists in real usage or do the check for it's existence I mentioned above.
Glad to hear that helped, just let me know if you have any further questions.
Hello, I'm facing an issue with
Fog.mock!
not mocking s3 commands. To reproduce the issue:Gemfile
is:report.rb
:Output of
bundle exec ruby report.rb
is:(line 14 is
file = bucket.files.create({ key: path, body: 'test_body', public: true })
)It runs smooth without the Fog.mock!
Any idea how to fix that ?
Thanks, and thanks for the good job on that gem. Loïc