plugintest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package plugintest provides a test harness for plugin authors to mount their ResourcePluginConfig and assert behavior (CRUD, watch events, health, relationships) without needing gRPC or process spawning.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness[ClientT any] struct {
	// contains filtered or unexported fields
}

Harness wraps a resource controller and a recording sink, providing a fluent test API for plugin authors.

func Mount

func Mount[ClientT any](t *testing.T, cfg resource.ResourcePluginConfig[ClientT], opts ...Option[ClientT]) *Harness[ClientT]

Mount builds a resource controller from the given config and returns a Harness ready for testing. The harness starts a background event listener so that watch events are automatically captured by the recording sink.

func (*Harness[ClientT]) Close

func (h *Harness[ClientT]) Close()

Close cancels the harness context and shuts down the controller if it implements io.Closer (the concrete resourceController does).

func (*Harness[ClientT]) Context

func (h *Harness[ClientT]) Context() context.Context

Context returns the harness's context, useful for injecting session data.

func (*Harness[ClientT]) Create

func (h *Harness[ClientT]) Create(key string, input resource.CreateInput) *resource.CreateResult

Create delegates to the controller's Create method.

func (*Harness[ClientT]) Delete

func (h *Harness[ClientT]) Delete(key string, input resource.DeleteInput) *resource.DeleteResult

Delete delegates to the controller's Delete method.

func (*Harness[ClientT]) ExecuteAction

func (h *Harness[ClientT]) ExecuteAction(key, actionID string, input resource.ActionInput) *resource.ActionResult

ExecuteAction executes a resource action through the controller.

func (*Harness[ClientT]) Get

func (h *Harness[ClientT]) Get(key string, input resource.GetInput) *resource.GetResult

Get delegates to the controller's Get method.

func (*Harness[ClientT]) GetHealth

func (h *Harness[ClientT]) GetHealth(connID, key string, data json.RawMessage) *resource.ResourceHealth

GetHealth assesses health for a resource from raw data.

func (*Harness[ClientT]) GetRelationships

func (h *Harness[ClientT]) GetRelationships(key string) []resource.RelationshipDescriptor

GetRelationships returns declared relationship descriptors for a resource type.

func (*Harness[ClientT]) List

func (h *Harness[ClientT]) List(key string, input resource.ListInput) *resource.ListResult

List delegates to the controller's List method.

func (*Harness[ClientT]) LoadConnections

func (h *Harness[ClientT]) LoadConnections() []types.Connection

LoadConnections loads connections from config.

func (*Harness[ClientT]) Provider

func (h *Harness[ClientT]) Provider() resource.Provider

Provider returns the underlying resource.Provider for direct access.

func (*Harness[ClientT]) Sink

func (h *Harness[ClientT]) Sink() *resourcetest.RecordingSink

Sink returns the underlying RecordingSink for advanced assertions.

func (*Harness[ClientT]) StartConnection

func (h *Harness[ClientT]) StartConnection(id string) types.ConnectionStatus

StartConnection starts a connection and returns its status.

func (*Harness[ClientT]) StopConnection

func (h *Harness[ClientT]) StopConnection(id string)

StopConnection stops a connection.

func (*Harness[ClientT]) Update

func (h *Harness[ClientT]) Update(key string, input resource.UpdateInput) *resource.UpdateResult

Update delegates to the controller's Update method.

func (*Harness[ClientT]) WaitForAdds

func (h *Harness[ClientT]) WaitForAdds(count int, timeout time.Duration)

WaitForAdds blocks until at least count add events are recorded.

func (*Harness[ClientT]) WaitForDeletes

func (h *Harness[ClientT]) WaitForDeletes(count int, timeout time.Duration)

WaitForDeletes blocks until at least count delete events are recorded.

func (*Harness[ClientT]) WaitForUpdates

func (h *Harness[ClientT]) WaitForUpdates(count int, timeout time.Duration)

WaitForUpdates blocks until at least count update events are recorded.

type Option

type Option[ClientT any] func(*harnessConfig[ClientT])

Option configures a Harness.

func WithContext

func WithContext[ClientT any](ctx context.Context) Option[ClientT]

WithContext sets a parent context for the harness.

func WithTimeout

func WithTimeout[ClientT any](d time.Duration) Option[ClientT]

WithTimeout sets the default timeout for wait operations.

Jump to

Keyboard shortcuts

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