Documentation
¶
Overview ¶
Package gcstest provides a lightweight in-memory GCS server for unit tests, backed by fakestorage (fsouza/fake-gcs-server) over an [httptest.Server].
Use New to start a server. It is automatically shut down when the test completes. Unlike S3, GCS has no create-on-write semantics, so provision buckets with Server.CreateBucket before use, then point an objectstore GCS config at the server via Server.Endpoint:
srv := gcstest.New(t)
srv.CreateBucket("my-bucket")
client, err := objectstore.NewWithConfig(&objectstore.Config{
Backend: objectstore.BackendGCS,
Bucket: "my-bucket",
Endpoint: srv.Endpoint(),
})
With no credentials configured, the provider connects to the server anonymously.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an in-memory GCS server backed by fakestorage.
func New ¶
New starts an in-memory GCS server over plain HTTP and registers tb.Cleanup to shut it down when the test completes.
func (*Server) CreateBucket ¶
CreateBucket provisions a bucket in the in-memory server. GCS has no create-on-write semantics, so tests must create a bucket before writing to it.
func (*Server) Endpoint ¶
Endpoint returns the GCS JSON API base URL of the in-memory server, already including the "/storage/v1/" suffix the SDK expects. Pass this as [objectstore.Config.Endpoint].
func (*Server) Fake ¶
func (s *Server) Fake() *fakestorage.Server
Fake returns the underlying fakestorage.Server for tests that need to seed or inspect objects directly without going through the GCS client.