mirror of
https://github.com/fsouza/fake-gcs-server.git
synced 2026-04-25 13:45:52 +03:00
[GH-ISSUE #24] How to use the server? #2159
Labels
No labels
bug
compatibility-issue
docker
documentation
enhancement
help wanted
needs information
pull-request
question
stale
unfortunate
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/fake-gcs-server#2159
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rogierlommers on GitHub (Mar 28, 2019).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/24
Hey! Nice project, appreciate it!
But I'm wondering: how can I use the server in my go apps? For example, I can use the pubsub emulator by setting the
PUBSUB_EMULATOR_HOSTto the address where the pubsub emulator is running. This wat the client directly connects to the one running on that port. Is there also some kind of mechanism for the Go storage SDK?In other words: how can I point the client to the emulated server?
I tried to set the options while creating the storage client, but I can only override the endpoint. Not the hostname + port.
@fsouza commented on GitHub (Mar 28, 2019):
Hey, you should call the Client() method on the fake server instance, that will give you a storage.Client instance pre-configured to talk to the server.
Example from the docs: https://godoc.org/github.com/fsouza/fake-gcs-server/fakestorage#example-Server-Client
Some projects that use it:
gcs-helper
github.com/nytimes/gcs-helper@784d637554/vodmodule/mapper.go (L22)github.com/nytimes/gcs-helper@784d637554/vodmodule/mapper_test.go (L109)porteiro
github.com/fsouza/porteiro@57052b847a/gcs/gcs.go (L47)github.com/fsouza/porteiro@57052b847a/gcs/gcs_test.go (L30)@rogierlommers commented on GitHub (Mar 28, 2019):
Ok, clear. This would mean that my Go code should contain something like:
"if running locally, then use this client" (coming from the
client()-method. The nice part of the pubsub emulator stuff is that it's just an environment var which sets emulation ON/OFF.@fsouza commented on GitHub (Mar 28, 2019):
Oh so this is not for automated tests? In that case, you're probably looking for something like https://github.com/teone/gc-fake-storage, that gives you a standalone process that starts a fake server that you can point to.
@rogierlommers commented on GitHub (Mar 29, 2019):
Yeah, that's exactly what I need. But unfortunately I can't get it to work. So I did the following:
First, I started the docker container (the fake server):
docker run -d --name gc-fake-storage -p 4443:4443 -v /tmp/data:/data matteoscandolo/gc-fake-storage:0.1.0Then I tried to create a bucket using the normal Go SDK. The code is like this:
Unfortunately this does not work. I keep receiving this error:
FATA[0000] bucket creation error: googleapi: got HTTP response code 404 with body: 404 page not found. Any ideas about what I'm doing wrong?@jwhitlock commented on GitHub (Jun 5, 2019):
@rogierlommers
bucket.Createwould not have worked before PR #34 was merged. Now thePOSTto/storage/v1/bto create a bucket should work.In
gc-fake-storage, I believe I continued to get 404s unless the directory/storage/was created first. This can be created as a side effect of providing a/datamount. A single/data/first_bucket/first_object.txtwould create the/storagefolder, a bucketfirst_bucket, and a blob / objectfirst_object.txtin that bucket. I've submitted https://github.com/teone/gc-fake-storage/pull/3 to fix that.@fsouza commented on GitHub (Jul 18, 2019):
README now has instructions on how to use the emulator locally with Docker. Closing this issue, but feel free to open a new one in case of questions!