sdbtestcontainer

package
v1.56.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sdbtestcontainer provides a testcontainers module for SpiceDB.

It runs `spicedb serve` (in-memory datastore by default) with a randomized preshared key, exposing the gRPC endpoint and preshared key via methods. Pass WithHTTP to additionally enable and expose the HTTP gateway.

Index

Constants

View Source
const (
	// DefaultImage is the SpiceDB Docker image repository.
	DefaultImage = "authzed/spicedb"
	// DefaultTag is the default SpiceDB Docker image tag.
	DefaultTag = "latest"
	// DefaultImageReference is the fully-qualified default image.
	DefaultImageReference = DefaultImage + ":" + DefaultTag
)

Variables

This section is empty.

Functions

func WithBootstrapRelationships

func WithBootstrapRelationships(relationships ...string) testcontainers.ContainerCustomizer

WithBootstrapRelationships writes the given relationships (in SpiceDB relationship string form, e.g. "resource:foo#reader@user:bar") once the server is ready. Each is written as a TOUCH. Requires a schema that defines the referenced relations, typically supplied via WithBootstrapSchema.

func WithBootstrapSchema

func WithBootstrapSchema(schema string) testcontainers.ContainerCustomizer

WithBootstrapSchema writes the given schema to the server once it is ready, over the gRPC API using the configured preshared key.

func WithDatastore

func WithDatastore(engine, connURI string) testcontainers.ContainerCustomizer

WithDatastore overrides the datastore engine and connection URI. By default SpiceDB runswith the in-memory datastore and no connection URI is passed.

func WithHTTP

WithHTTP enables the SpiceDB HTTP gateway. The HTTP port is exposed and mapped, and Container.HTTPEndpoint returns the reachable host:port.

func WithLogLevel

func WithLogLevel(level string) testcontainers.ContainerCustomizer

WithLogLevel sets the SpiceDB --log-level flag (e.g. "debug", "info", "warn").

func WithPresharedKeys

func WithPresharedKeys(keys ...string) testcontainers.ContainerCustomizer

WithPresharedKeys overrides the gRPC preshared key. By default Run generates a random key, retrievable via Container.PresharedKey.

Types

type Container

type Container struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

Container is a running SpiceDB server. Call Terminate to stop it.

func Run

Run starts a SpiceDB server and waits for it to accept connections.

img is the image to run (use DefaultImageReference for the default). opts may be any testcontainers.ContainerCustomizer; the WithXxx options in this package configure SpiceDB-specific behavior, while generic customizers are applied to the underlying container request. For flags this module does not model directly, pass testcontainers.WithEnv with the corresponding SPICEDB_* vars.

func (*Container) GRPCEndpoint

func (c *Container) GRPCEndpoint() string

Endpoint returns the gRPC endpoint as "host:port", reachable from the host.

func (*Container) HTTPEndpoint

func (c *Container) HTTPEndpoint() string

HTTPEndpoint returns the HTTP gateway endpoint as "host:port", reachable from the host. It returns an empty string if the HTTP gateway was not enabled via WithHTTP.

func (*Container) PresharedKey

func (c *Container) PresharedKey() string

PresharedKey returns the first gRPC preshared key the server was started with. Use it as a bearer token when authenticating API calls.

Jump to

Keyboard shortcuts

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