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 ¶
- type CSMS
- func (s *CSMS) Actions(chargePointID string) []string
- func (s *CSMS) Call(ctx context.Context, chargePointID, action string, payload, result any) error
- func (s *CSMS) Calls(chargePointID string) []Call
- func (s *CSMS) Connects(chargePointID string) int
- func (s *CSMS) Drop(chargePointID string)
- func (s *CSMS) Handle(action string, fn HandlerFunc)
- func (s *CSMS) URL() string
- func (s *CSMS) WaitDisconnects(t testing.TB, chargePointID string, n int) []Disconnect
- func (s *CSMS) WaitForCalls(t testing.TB, chargePointID, action string, n int) []Call
- type Call
- type Disconnect
- type HandlerFunc
- type Option
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 ¶
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 ¶
Actions returns the actions of every call received so far from one charger, oldest first.
func (*CSMS) Call ¶
Call sends a request to a connected charger and decodes its answer into result, unless result is nil.
func (*CSMS) Drop ¶
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 ¶
URL returns the CSMS URL to configure chargers with. Chargers append their charge point ID to it.
func (*CSMS) WaitDisconnects ¶
WaitDisconnects waits until the charger's connections have ended at least n times and returns how each ended.
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 ¶
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 ¶
HeartbeatInterval sets the interval, in seconds, that the CSMS gives in its BootNotification answer. The default is 300.
func RequirePassword ¶
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.