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
- func WithBootstrapRelationships(relationships ...string) testcontainers.ContainerCustomizer
- func WithBootstrapSchema(schema string) testcontainers.ContainerCustomizer
- func WithDatastore(engine, connURI string) testcontainers.ContainerCustomizer
- func WithHTTP() testcontainers.ContainerCustomizer
- func WithLogLevel(level string) testcontainers.ContainerCustomizer
- func WithPresharedKeys(keys ...string) testcontainers.ContainerCustomizer
- type Container
Constants ¶
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 ¶
func WithHTTP() testcontainers.ContainerCustomizer
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 ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
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 ¶
Endpoint returns the gRPC endpoint as "host:port", reachable from the host.
func (*Container) HTTPEndpoint ¶
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 ¶
PresharedKey returns the first gRPC preshared key the server was started with. Use it as a bearer token when authenticating API calls.