gcstest

package
v2.29.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 2 Imported by: 0

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

func New(tb testing.TB) *Server

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

func (s *Server) CreateBucket(name string)

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

func (s *Server) Endpoint() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL