gocloud.devgocloud.dev/runtimevar/drivertest Index | Files

package drivertest

import "gocloud.dev/runtimevar/drivertest"

Package drivertest provides a conformance test for implementations of runtimevar.

Index

Functions

func RunConformanceTests

func RunConformanceTests(t *testing.T, newHarness HarnessMaker, asTests []AsTest)

RunConformanceTests runs conformance tests for driver implementations of runtimevar.

Types

type AsTest

type AsTest interface {
	// Name should return a descriptive name for the test.
	Name() string
	// SnapshotCheck will be called to allow verification of Snapshot.As.
	SnapshotCheck(s *runtimevar.Snapshot) error
	// ErrorCheck will be called to allow verification of Variable.ErrorAs.
	// driver is provided so that errors other than err can be checked;
	// Variable.ErrorAs won't work since it expects driver errors to be wrapped.
	ErrorCheck(v *runtimevar.Variable, err error) error
}

AsTest represents a test of As functionality. The conformance test: 1. Reads a Snapshot of the variable before it exists. 2. Calls ErrorCheck. 3. Creates the variable and reads a Snapshot of it. 4. Calls SnapshotCheck.

type Harness

type Harness interface {
	// MakeWatcher creates a driver.Watcher to watch the given variable.
	MakeWatcher(ctx context.Context, name string, decoder *runtimevar.Decoder) (driver.Watcher, error)
	// CreateVariable creates the variable with the given contents.
	CreateVariable(ctx context.Context, name string, val []byte) error
	// UpdateVariable updates an existing variable to have the given contents.
	UpdateVariable(ctx context.Context, name string, val []byte) error
	// DeleteVariable deletes an existing variable.
	DeleteVariable(ctx context.Context, name string) error
	// Close is called when the test is complete.
	Close()
	// Mutable returns true iff the driver supports UpdateVariable/DeleteVariable.
	// If false, those functions should return errors, and the conformance tests
	// will skip and/or ignore errors for tests that require them.
	Mutable() bool
}

Harness describes the functionality test harnesses must provide to run conformance tests.

type HarnessMaker

type HarnessMaker func(t *testing.T) (Harness, error)

HarnessMaker describes functions that construct a harness for running tests. It is called exactly once per test; Harness.Close() will be called when the test is complete.

type Message

type Message struct {
	Name, Text string
}

Message is used as a target for JSON decoding.

Source Files

drivertest.go

Version
v0.41.0
Published
Mar 30, 2025
Platform
js/wasm
Imports
9 packages
Last checked
4 hours ago

Tools for package owners.