mock

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package mock provides in-memory hal.HAL implementations for use in tests and simulation environments.

All fields are exported so tests can set initial state and inspect results directly. Methods are safe for concurrent use only if the test sets fields before calling [NewHAL] and does not mutate them afterwards; for race-free concurrent tests, protect shared state with a mutex in a custom sub-struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chassis

type Chassis struct {
	On              bool
	Intruded        bool
	ColdResets      int
	WarmResets      int
	PowerCycles     int
	LastIdentifySec uint8
	BootFlags       *types.BootOptionParam_BootFlags
	BootInfoAck     *types.BootOptionParam_BootInfoAcknowledge

	// Hook allows tests to inject custom behaviour.
	SetPowerHook func(on bool) error
	// contains filtered or unexported fields
}

Chassis is the mock hal.ChassisHAL.

func (*Chassis) ColdReset

func (c *Chassis) ColdReset(_ context.Context) error

func (*Chassis) GetBootFlags

GetBootFlags returns the last stored boot flags, or hal.ErrNotSupported when none have been set.

func (*Chassis) GetBootInfoAcknowledge

func (c *Chassis) GetBootInfoAcknowledge(_ context.Context) (*types.BootOptionParam_BootInfoAcknowledge, error)

GetBootInfoAcknowledge returns the last stored acknowledge data, or a default value when none have been stored.

func (*Chassis) Identify

func (c *Chassis) Identify(_ context.Context, seconds uint8) error

func (*Chassis) IntrusionState

func (c *Chassis) IntrusionState(_ context.Context) (bool, error)

func (*Chassis) PowerCycle

func (c *Chassis) PowerCycle(_ context.Context) error

PowerCycle performs a power cycle. The mock counts calls independently so tests can assert that Chassis Control action 0x02 dispatched here rather than to ColdReset. Real noop HALs that lack a distinct power-cycle operation may delegate to ColdReset; the mock keeps the counters separate for clarity.

func (*Chassis) PowerState

func (c *Chassis) PowerState(_ context.Context) (bool, error)

func (*Chassis) SetBootFlags

func (c *Chassis) SetBootFlags(_ context.Context, flags *types.BootOptionParam_BootFlags) error

SetBootFlags stores the full boot flags structure so tests and the reference server can round-trip Set/Get System Boot Options.

func (*Chassis) SetBootInfoAcknowledge

func (c *Chassis) SetBootInfoAcknowledge(_ context.Context, ack *types.BootOptionParam_BootInfoAcknowledge) error

SetBootInfoAcknowledge stores the boot info acknowledge data.

func (*Chassis) SetPower

func (c *Chassis) SetPower(_ context.Context, on bool) error

func (*Chassis) WarmReset

func (c *Chassis) WarmReset(_ context.Context) error

type GPIO

type GPIO struct {
	// contains filtered or unexported fields
}

GPIO is the mock hal.GPIOHAL.

func (*GPIO) Get

func (g *GPIO) Get(_ context.Context, pin string) (bool, error)

func (*GPIO) Set

func (g *GPIO) Set(_ context.Context, pin string, high bool) error

func (*GPIO) Watch

func (g *GPIO) Watch(_ context.Context, pin string, cb func(bool)) (func(), error)

type HAL

type HAL struct {
	// contains filtered or unexported fields
}

HAL is a fully in-memory hal.HAL.

func New

func New() *HAL

New returns a HAL with all sub-interfaces initialised. Each sub-type is also exported individually for targeted embedding.

func (*HAL) Chassis

func (h *HAL) Chassis() hal.ChassisHAL

func (*HAL) Close

func (h *HAL) Close() error

func (*HAL) GPIO

func (h *HAL) GPIO() hal.GPIOHAL

func (*HAL) I2C

func (h *HAL) I2C() hal.I2CHAL

func (*HAL) Network

func (h *HAL) Network() hal.NetworkHAL

func (*HAL) Sensors

func (h *HAL) Sensors() hal.SensorHAL

func (*HAL) Storage

func (h *HAL) Storage() hal.StorageHAL

type I2C

type I2C struct {
	ReadFunc func(bus int, addr, reg uint8, length int) ([]byte, error)
	Writes   []I2CWrite
	// contains filtered or unexported fields
}

I2C is the mock hal.I2CHAL. Reads return data from ReadFunc if set, otherwise ErrNotSupported.

func (*I2C) Read

func (i *I2C) Read(_ context.Context, bus int, addr, reg uint8, length int) ([]byte, error)

func (*I2C) Write

func (i *I2C) Write(_ context.Context, bus int, addr, reg uint8, data []byte) error

type I2CWrite

type I2CWrite struct {
	Bus  int
	Addr uint8
	Reg  uint8
	Data []byte
}

I2CWrite records a single I2C write for test assertions.

type Network

type Network struct {
	Cfg hal.IPConfig
	// contains filtered or unexported fields
}

Network is the mock hal.NetworkHAL.

func (*Network) GetConfig

func (n *Network) GetConfig(_ context.Context) (*hal.IPConfig, error)

func (*Network) SetConfig

func (n *Network) SetConfig(_ context.Context, cfg *hal.IPConfig) error

type Sensors

type Sensors struct {
	Values map[uint8]uint8
	Descs  []hal.SensorDescriptor
	// contains filtered or unexported fields
}

Sensors is the mock hal.SensorHAL.

func (*Sensors) List

func (s *Sensors) List(_ context.Context) ([]hal.SensorDescriptor, error)

func (*Sensors) ReadRaw

func (s *Sensors) ReadRaw(_ context.Context, id uint8) (uint8, error)

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage is the mock hal.StorageHAL.

func (*Storage) FRU

func (s *Storage) FRU() hal.FRUStore

func (*Storage) SDR

func (s *Storage) SDR() hal.SDRStore

Jump to

Keyboard shortcuts

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