testharness

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testharness contains opt-in Docker API fault-injection helpers.

Index

Constants

View Source
const (
	LabelRun     = "io.carbon-panel.fault-harness.run"
	LabelInstall = "io.carbon-panel.fault-harness.install"
	LabelNode    = "io.carbon-panel.fault-harness.node"
)
View Source
const ManifestVersion = 1

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(ctx context.Context, manifest *Manifest, endpoints map[string]string) error

Cleanup removes only IDs listed in the manifest after confirming each object's daemon identity and all three ownership labels. It never prunes or enumerates.

func WriteManifest

func WriteManifest(path string, manifest *Manifest) error

WriteManifest writes atomically and refuses to overwrite an existing run file.

Types

type Daemon

type Daemon struct {
	Alias         string `json:"alias"`
	ID            string `json:"id"`
	DockerRootDir string `json:"docker_root_dir"`
	ServerVersion string `json:"server_version"`
}

Daemon is a qualified Engine identity. Alias maps to endpoint-a or endpoint-b.

type FaultKind

type FaultKind string

FaultKind describes where the proxy interrupts a Docker API exchange.

const (
	// DropBefore closes the client connection without sending a request upstream.
	DropBefore FaultKind = "drop-before"
	// DelayBefore waits before forwarding; a client deadline can cancel the request
	// before the daemon sees it.
	DelayBefore FaultKind = "delay-before"
	// DropAfter forwards the full request, consumes the daemon response, then drops
	// the client connection. Mutations may have committed and the result is ambiguous.
	DropAfter FaultKind = "drop-after"
	// DelayAfter forwards the request, waits for the daemon response, then delays
	// delivery. A client timeout at this point is also an ambiguous result.
	DelayAfter FaultKind = "delay-after"
	// PullErrorStream appends a Docker JSON progress/error frame to an image-pull
	// stream while preserving the HTTP status and streaming response shape.
	PullErrorStream FaultKind = "pull-error-stream"
	// DisconnectOnce drops the first matching streaming request. Later requests pass.
	DisconnectOnce FaultKind = "disconnect-once"
)

type Manifest

type Manifest struct {
	Version   int             `json:"version"`
	RunID     string          `json:"run_id"`
	InstallID string          `json:"install_id"`
	NodeID    string          `json:"node_id"`
	CreatedAt time.Time       `json:"created_at"`
	Daemons   []Daemon        `json:"daemons"`
	Resources []OwnedResource `json:"resources"`
}

Manifest records the owner and daemon identity for every disposable resource. Endpoints are deliberately kept outside the file because they can contain credentials; callers supply endpoints again when cleaning up.

func NewManifest

func NewManifest(ctx context.Context, endpointA, endpointB, installID, nodeID, runID string) (*Manifest, error)

NewManifest verifies both endpoints are available, identify different daemons, and report different Docker roots before returning a manifest.

func ReadManifest

func ReadManifest(path string) (*Manifest, error)

ReadManifest parses and validates the version and required ownership fields.

func (*Manifest) AddResource

func (m *Manifest) AddResource(resource OwnedResource) error

AddResource records an exact object only when its ownership labels match this run.

func (*Manifest) OwnershipLabels

func (m *Manifest) OwnershipLabels() map[string]string

OwnershipLabels returns the complete identifying label set for an owned object.

type OwnedResource

type OwnedResource struct {
	DaemonAlias string            `json:"daemon_alias"`
	Kind        string            `json:"kind"`
	ID          string            `json:"id"`
	Name        string            `json:"name,omitempty"`
	Labels      map[string]string `json:"labels"`
}

OwnedResource identifies one exact Docker object eligible for scoped cleanup.

type Proxy

type Proxy struct {
	Target   *url.URL
	Listener net.Listener
	// contains filtered or unexported fields
}

Proxy forwards Docker Engine HTTP requests to Target and injects configured faults. It does not understand or rewrite Docker API bodies except for the explicit pull error stream rule.

func NewProxy

func NewProxy(target string, rules []Rule) (*Proxy, error)

NewProxy binds a loopback listener and starts a protocol-level HTTP proxy. Target must be an HTTP(S) Docker Engine API endpoint (not a CLI context name).

func (*Proxy) Close

func (p *Proxy) Close() error

Close stops the listener and releases transport connections.

func (*Proxy) URL

func (p *Proxy) URL() string

URL is the loopback URL for the proxy.

type Rule

type Rule struct {
	Method     string
	PathPrefix string
	Kind       FaultKind
	Times      int
	Delay      time.Duration
	Error      string
}

Rule matches a request and applies Kind at most Times times. A non-positive Times means once. PathPrefix should generally include Docker's /vX.Y prefix.

Jump to

Keyboard shortcuts

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