testutils

package
v1.12.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testutils provides shared helpers for cluster command tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConfigManager

func CreateConfigManager(t *testing.T, writer io.Writer) *ksailconfigmanager.ConfigManager

CreateConfigManager creates a config manager for testing with a valid ksail config.

func NewCommand

func NewCommand(t *testing.T) (*cobra.Command, *bytes.Buffer)

NewCommand creates a test command with output buffers.

func RunValidationErrorTest

func RunValidationErrorTest(
	t *testing.T,
	commandFactory func() *cobra.Command,
	expectedSubstrings ...string,
)

RunValidationErrorTest executes the provided command factory in an empty directory and validates error output.

func SetupValidWorkingDir

func SetupValidWorkingDir(t *testing.T) func()

SetupValidWorkingDir creates a valid KSail configuration in a temporary directory and switches to it. The returned cleanup function restores the original working directory.

Types

type RecordingTimer

type RecordingTimer struct {
	StartCount    int
	NewStageCount int
}

RecordingTimer is a test double for timer.Timer that records method calls.

func (*RecordingTimer) GetTiming

func (r *RecordingTimer) GetTiming() (time.Duration, time.Duration)

GetTiming implements timer.Timer.

func (*RecordingTimer) NewStage

func (r *RecordingTimer) NewStage()

NewStage implements timer.Timer.

func (*RecordingTimer) Start

func (r *RecordingTimer) Start()

Start implements timer.Timer.

func (*RecordingTimer) Stop

func (r *RecordingTimer) Stop()

Stop implements timer.Timer.

type StubFactory

type StubFactory struct {
	Provisioner        clusterprovisioner.ClusterProvisioner
	DistributionConfig any
	Err                error
	CallCount          int
}

StubFactory is a test double for clusterprovisioner.Factory.

func (*StubFactory) Create

Create implements clusterprovisioner.Factory.

type StubProvisioner

type StubProvisioner struct {
	CreateErr     error
	CreateCalls   int
	DeleteErr     error
	DeleteCalls   int
	StartErr      error
	StartCalls    int
	StopErr       error
	StopCalls     int
	ReceivedNames []string
}

StubProvisioner is a test double for clusterprovisioner.ClusterProvisioner.

func (*StubProvisioner) Create

func (p *StubProvisioner) Create(_ context.Context, name string) error

Create implements clusterprovisioner.ClusterProvisioner.

func (*StubProvisioner) Delete

func (p *StubProvisioner) Delete(_ context.Context, name string) error

Delete implements clusterprovisioner.ClusterProvisioner.

func (*StubProvisioner) Exists

Exists implements clusterprovisioner.ClusterProvisioner.

func (*StubProvisioner) List

func (p *StubProvisioner) List(context.Context) ([]string, error)

List implements clusterprovisioner.ClusterProvisioner.

func (*StubProvisioner) Start

func (p *StubProvisioner) Start(_ context.Context, name string) error

Start implements clusterprovisioner.ClusterProvisioner.

func (*StubProvisioner) Stop

func (p *StubProvisioner) Stop(_ context.Context, name string) error

Stop implements clusterprovisioner.ClusterProvisioner.

Jump to

Keyboard shortcuts

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