dialtest

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 35 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dialtest is the test support of the kinds of segment store (`segmentstore.Kind`): a loopback store that speaks enough RESP for go-redis and valkey-go, and the cases that every kind must pass, run by the tests of each kind (`redisdial`, `valkeydial`) in its own package, so that each is measured by its own tests.

Index

Constants

View Source
const (
	// WaitFor is the bound of a wait of a test for an outcome that must come.
	WaitFor = 10 * time.Second
	// Tick is the retry interval of the dial loop in the tests.
	Tick = 5 * time.Millisecond
)
View Source
const (
	// Password is the secret of the connections of the suite: it must be in no error and in no span.
	Password = "s3cr3t-pass"
)

Variables

This section is empty.

Functions

func AssertClientSpans

func AssertClientSpans(t *testing.T, sink *tracetest.SpanRecorder, parent trace.SpanContext, secrets ...string)

AssertClientSpans checks the spans that the sink recorded: the spans that are children of parent exist, are client spans of the trace of parent, and no span carries one of the secrets in any text.

func CABundles

func CABundles(t *testing.T) func(string) ([]byte, error)

CABundles serves the CA bundle files of the suite: "/ca.pem" is a real certificate, "/notpem" is not PEM, and any other name cannot be read.

func Connection

func Connection(t *testing.T, suite Suite, address, extra string) *bootstrap.Connection

Connection parses one connection named "store" of the kind: its addresses, the settings of the suite, and extra (more settings, may be empty).

func Kinds

func Kinds(t *testing.T, kinds ...segmentstore.Kind) segmentstore.Kinds

Kinds are the kinds of the arguments by type.

func NewTracing

func NewTracing(t *testing.T) (tracing.Providers, *tracetest.SpanRecorder)

NewTracing returns tracing providers that record into the returned recorder; they are shut down with the test.

func Run

func Run(t *testing.T, suite Suite)

Run runs the cases that every kind of segment store passes, as subtests of t.

func SecretEnv

func SecretEnv(name string) (string, bool)

SecretEnv serves the password of the connections of the suite and nothing else.

func StateOf

func StateOf(conns *segmentstore.Connections, name string) string

StateOf is the state of the connection of that name, empty for a name that has none.

Types

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

Cluster is stubs that answer as the nodes of a Redis cluster do (CLUSTER SLOTS, MOVED).

func StartCluster

func StartCluster(t *testing.T, n int) *Cluster

StartCluster starts a cluster of n stubs.

func (*Cluster) Addresses

func (c *Cluster) Addresses() []string

Addresses are the host:port of the nodes.

func (*Cluster) Delete

func (c *Cluster) Delete(key string)

Delete removes a key from the node that owns its slot.

func (*Cluster) Nodes

func (c *Cluster) Nodes() []*Stub

Nodes are the stubs of the cluster, in slot order.

func (*Cluster) Put

func (c *Cluster) Put(key, value string)

Put sets a key on the node that owns its slot (any node routes it).

type Stub

type Stub struct {
	// contains filtered or unexported fields
}

Stub is a loopback store. Its listener is open from the start and it is closed when the test ends. It speaks the handshake of go-redis and valkey-go (HELLO, CLIENT, SELECT, CLUSTER, PING) and the commands of the segment providers (SMISMEMBER, GET) over the sets and values it was given; Stub.Answer replaces every reply.

func StartStub

func StartStub(t *testing.T, sets map[string][]string, values map[string]string) *Stub

StartStub starts a stub that holds the sets (a key and its members) and the string values (a key and its value).

func StartTLSStub

func StartTLSStub(t *testing.T, sets map[string][]string, values map[string]string) (*Stub, []byte)

StartTLSStub is StartStub over TLS: the certificate of the stub (for 127.0.0.1) is signed by a CA that is the second result, a PEM bundle.

func (*Stub) Address

func (s *Stub) Address() string

Address is the host:port of the stub.

func (*Stub) Answer

func (s *Stub) Answer(raw string)

Answer makes the stub reply to every command, the handshake included, with raw (RESP bytes); an empty reply makes it close the connection at the first command, like a store that is not a store.

func (*Stub) Commands

func (s *Stub) Commands() [][]string

Commands is the commands the stub received, each as its arguments, in order.

func (*Stub) Delete

func (s *Stub) Delete(key string)

Delete removes a key, as DEL does.

func (*Stub) FailCommand

func (s *Stub) FailCommand(name, raw string)

FailCommand makes every command of that name (SCAN, GET) answer with raw until it is called again with an empty reply.

func (*Stub) FailKey

func (s *Stub) FailKey(key, raw string)

FailKey makes every GET of the key answer with raw (RESP bytes, for example "-NOPERM no permission\r\n") until it is called again for the key with an empty reply.

func (*Stub) HoldKey

func (s *Stub) HoldKey(key string, hold func(ctx context.Context))

HoldKey makes a GET of the key call hold before it is answered, with a context that ends when the client closes the connection (a cancelled or timed out read); the answer follows when hold returns. A nil hold clears it.

func (*Stub) Put

func (s *Stub) Put(key, value string)

Put sets the string value of a key, as SET does.

func (*Stub) PutSet

func (s *Stub) PutSet(key string, members ...string)

PutSet makes the key a set, which a GET answers with WRONGTYPE.

func (*Stub) RequireAuth

func (s *Stub) RequireAuth(user, password string)

RequireAuth makes the stub refuse every command of a connection that did not authenticate with the user (empty for the default user) and the password: HELLO 3 AUTH or AUTH. A connection that is open keeps its login when the password changes, as on a real server.

func (*Stub) StallKey

func (s *Stub) StallKey(key string, stall func(ctx context.Context))

StallKey makes a GET of the key answer in two parts: the size of the value and the first half of it, then a call of stall, with a context that ends when the client closes the connection, then the rest. A nil stall clears it.

type Suite

type Suite struct {
	// Kind is the kind under test.
	Kind segmentstore.Kind
	// Unavailable is the error that a dial of a store that cannot be reached wraps: the sentinel of the provider
	// package of the kind.
	Unavailable error
	// Settings are the settings that a connection of the kind needs besides its addresses, as the body of a YAML flow
	// mapping (a connection of the kind that fails fast, for example); may be empty.
	Settings string
}

Suite describes a kind for Run.

Jump to

Keyboard shortcuts

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