iactest

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package iactest provides shared fakes for tests that exercise the IaCProvider / ResourceDriver contract. Lifting these out of individual test files prevents the no-op-stub proliferation that otherwise occurs every time a new package needs to satisfy the interface (one no-op was already duplicated three times across this repo before consolidation).

The types here are deliberately minimal: each method returns a zero value or a caller-configured field. Tests that need richer behavior should compose these (embed the struct and override specific methods) rather than introducing a parallel implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopDriver

type NoopDriver struct {
	// DiffResult is returned from Diff(). When nil with DiffErr also nil,
	// callers receive the plain (nil, nil) shape (treated by ComputePlan
	// as "no changes — skip").
	DiffResult *interfaces.DiffResult

	// DiffErr is returned from Diff() when set; takes precedence over
	// DiffResult.
	DiffErr error

	// DeleteErr is returned from Delete() when set. The default zero
	// value (nil) makes Delete a no-op success — matching the rest of
	// the NoopDriver shape.
	DeleteErr error

	// ReadResult is returned from Read(). When nil with ReadErr also
	// nil, callers receive the plain (nil, nil) shape that pre-T7.5
	// code expects from the Noop fake. Tests that exercise
	// iac/refreshoutputs.Refresh set this to a *ResourceOutput whose
	// Outputs map carries the live-shape keys the scenario asserts
	// reconciliation for.
	ReadResult *interfaces.ResourceOutput

	// ReadErr is returned from Read() when set; takes precedence over
	// ReadResult.
	ReadErr error

	// DiffCallCount is bumped on every Diff invocation. Exposed via
	// atomic.Int64 so cache-hit tests under -race do not need separate
	// synchronization.
	DiffCallCount atomic.Int64

	// DeleteCallCount is bumped on every Delete invocation. Exposed via
	// atomic.Int64 so dispatch-coverage tests (e.g.,
	// iac/conformance/scenarios_test.go) under -race can assert
	// driver.Delete was invoked without separate synchronization.
	DeleteCallCount atomic.Int64

	// ReadCallCount is bumped on every Read invocation. Exposed via
	// atomic.Int64 so refresh-outputs tests can assert driver.Read was
	// dispatched without separate synchronization.
	ReadCallCount atomic.Int64
}

NoopDriver is a minimal interfaces.ResourceDriver whose Diff method returns DiffResult (or DiffErr when set) and tracks call count so cache-hit tests can assert deduplication. Other lifecycle methods (Delete, Read) also bump per-method counters and accept a configured return value, so dispatch-coverage tests (notably iac/conformance/scenario_delete_action.go and iac/conformance/scenario_outputs_refresh.go) can pin driver-side invocation and observe live-shape reconciliation. Methods without an explicit counter return zero values.

func (*NoopDriver) Create

Create returns (nil, nil).

func (*NoopDriver) Delete

Delete bumps DeleteCallCount and returns DeleteErr (nil by default). The counter is the dispatch-coverage hook used by conformance scenarios that need to assert the v2 apply path actually reached driver.Delete (closing the latent gap from T3.3 where DOProvider's case-arm-less dispatch silently skipped Delete).

func (*NoopDriver) Diff

Diff bumps DiffCallCount and returns the configured DiffResult/DiffErr pair (DiffErr takes precedence when non-nil).

func (*NoopDriver) HealthCheck

HealthCheck returns (nil, nil).

func (*NoopDriver) Read

Read bumps ReadCallCount and returns the configured ReadResult/ ReadErr pair (ReadErr takes precedence when non-nil). The (nil, nil) shape is preserved when neither field is set, matching pre-T7.5 callers that only need the no-op signature.

func (*NoopDriver) Scale

Scale returns (nil, nil).

func (*NoopDriver) SensitiveKeys

func (d *NoopDriver) SensitiveKeys() []string

SensitiveKeys returns nil.

func (*NoopDriver) Update

Update returns (nil, nil).

type NoopProvider

type NoopProvider struct {
	// Driver, when non-nil, is returned from ResourceDriver(typ) for
	// every resource type. Leave nil for the pure-no-op shape used by
	// callers that only need to satisfy the interface signature.
	Driver *NoopDriver

	// ProviderName overrides the Name() return value. Defaults to
	// "iactest-noop" when empty.
	ProviderName string

	// ProviderVersion overrides the Version() return value. Defaults
	// to "0.0.0-iactest" when empty.
	ProviderVersion string

	// DispatchVersion is the value returned from ComputePlanVersion(),
	// satisfying iac/wfctlhelpers.ComputePlanVersionDeclarer. Tests
	// driving the v2 apply path set this to "v2"; leaving it empty
	// (the default) routes through the legacy v1 dispatch.
	DispatchVersion string
}

NoopProvider is a minimal interfaces.IaCProvider whose every method returns the zero value (nil error, nil result). It satisfies the interface for compile-time checks and exists so callers do not need to hand-roll a 14-method shell every time they need a placeholder.

When a test needs to observe Diff dispatch or driver behavior, supply a non-nil Driver — ResourceDriver(typ) returns it for any resource type — and configure that driver's behavior via NoopDriver fields.

func (*NoopProvider) Apply

Apply returns (nil, nil).

func (*NoopProvider) BootstrapStateBackend

func (p *NoopProvider) BootstrapStateBackend(_ context.Context, _ map[string]any) (*interfaces.BootstrapResult, error)

BootstrapStateBackend returns (nil, nil).

func (*NoopProvider) Capabilities

func (p *NoopProvider) Capabilities() []interfaces.IaCCapabilityDeclaration

Capabilities returns nil.

func (*NoopProvider) Close

func (p *NoopProvider) Close() error

Close is a no-op.

func (*NoopProvider) ComputePlanVersion

func (p *NoopProvider) ComputePlanVersion() string

ComputePlanVersion satisfies iac/wfctlhelpers.ComputePlanVersionDeclarer. Returns DispatchVersion (which defaults to "" — treated as v1 by the dispatcher).

func (*NoopProvider) Destroy

Destroy returns (nil, nil).

func (*NoopProvider) DetectDrift

DetectDrift returns (nil, nil).

func (*NoopProvider) Import

Import returns (nil, nil).

func (*NoopProvider) Initialize

func (p *NoopProvider) Initialize(_ context.Context, _ map[string]any) error

Initialize is a no-op.

func (*NoopProvider) Name

func (p *NoopProvider) Name() string

Name returns ProviderName when set, otherwise "iactest-noop".

func (*NoopProvider) Plan

Plan returns (nil, nil).

func (*NoopProvider) ResolveSizing

ResolveSizing returns (nil, nil).

func (*NoopProvider) ResourceDriver

func (p *NoopProvider) ResourceDriver(_ string) (interfaces.ResourceDriver, error)

ResourceDriver returns Driver (which may be nil — callers that dispatch Diff against the result must guard nil). Returning nil with no error matches the contract platform.ComputePlan tolerates: a missing driver for a resource type means the plan falls back to the legacy compare.

func (*NoopProvider) Status

Status returns (nil, nil).

func (*NoopProvider) SupportedCanonicalKeys

func (p *NoopProvider) SupportedCanonicalKeys() []string

SupportedCanonicalKeys returns nil.

func (*NoopProvider) Version

func (p *NoopProvider) Version() string

Version returns ProviderVersion when set, otherwise "0.0.0-iactest".

Jump to

Keyboard shortcuts

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