csmstest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package csmstest provides a fake CSMS for tests: an in-process WebSocket server that records every message chargers send, answers them, and can send requests of its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSMS

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

CSMS is a running fake CSMS.

func Start

func Start(t testing.TB, opts ...Option) *CSMS

Start runs a fake CSMS until the test ends. By default it accepts every charger and every tag, numbers transactions from 1, and answers BootNotification, Heartbeat, StatusNotification, Authorize, StartTransaction, StopTransaction and MeterValues.

func (*CSMS) Actions

func (s *CSMS) Actions(chargePointID string) []string

Actions returns the actions of every call received so far from one charger, oldest first.

func (*CSMS) Call

func (s *CSMS) Call(ctx context.Context, chargePointID, action string, payload, result any) error

Call sends a request to a connected charger and decodes its answer into result, unless result is nil.

func (*CSMS) Calls

func (s *CSMS) Calls(chargePointID string) []Call

Calls returns every call received so far from one charger, oldest first.

func (*CSMS) Connects

func (s *CSMS) Connects(chargePointID string) int

Connects returns how many times the charger has connected.

func (*CSMS) Drop

func (s *CSMS) Drop(chargePointID string)

Drop cuts the charger's connection without a close handshake, as a network failure would.

func (*CSMS) Handle

func (s *CSMS) Handle(action string, fn HandlerFunc)

Handle sets how the CSMS answers an action, replacing any earlier handler.

func (*CSMS) URL

func (s *CSMS) URL() string

URL returns the CSMS URL to configure chargers with. Chargers append their charge point ID to it.

func (*CSMS) WaitDisconnects

func (s *CSMS) WaitDisconnects(t testing.TB, chargePointID string, n int) []Disconnect

WaitDisconnects waits until the charger's connections have ended at least n times and returns how each ended.

func (*CSMS) WaitForCalls

func (s *CSMS) WaitForCalls(t testing.TB, chargePointID, action string, n int) []Call

WaitForCalls waits until the charger has sent at least n calls of the given action and returns those calls. It fails the test if that does not happen in time.

type Call

type Call struct {
	ChargePointID string
	Action        string
	Payload       json.RawMessage
	Time          time.Time
}

Call is one request a charger sent to the CSMS.

func (Call) Decode

func (c Call) Decode(t testing.TB, v any)

Decode reads the call's payload into v.

type Disconnect

type Disconnect struct {
	// Clean is true when the charger closed the WebSocket with a normal
	// close handshake, and false when the connection simply went away.
	Clean bool
}

Disconnect describes how one connection from a charger ended.

type HandlerFunc

type HandlerFunc func(chargePointID string, payload json.RawMessage) (any, *ocppj.CallError)

HandlerFunc answers one action. It returns the result payload, or a CallError to answer with an error.

type Option

type Option func(*CSMS)

Option configures a fake CSMS.

func HeartbeatInterval

func HeartbeatInterval(seconds int) Option

HeartbeatInterval sets the interval, in seconds, that the CSMS gives in its BootNotification answer. The default is 300.

func RequirePassword

func RequirePassword(password string) Option

RequirePassword makes the CSMS demand HTTP Basic authentication with the charge point ID as user name and the given password.

func WithoutSubprotocol

func WithoutSubprotocol() Option

WithoutSubprotocol makes the CSMS accept connections without selecting the OCPP WebSocket subprotocol.

Jump to

Keyboard shortcuts

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