fake

package
v0.0.0-...-ce4e325 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fake implements a journal writer for testing which is decoupled from the system's journald.

The systemd project does not have any facilities to support testing of journal reader clients (although it has been requested: https://github.com/systemd/systemd/issues/14120) so we have to get creative. The systemd-journal-remote command reads serialized journal entries in the Journal Export Format and writes them to journal files. This format is well-documented and straightforward to generate.

Index

Constants

This section is empty.

Variables

View Source
var ErrCommandNotFound = errors.New("systemd-journal-remote command not found")

ErrCommandNotFound is returned when the systemd-journal-remote command could not be located at the well-known paths or $PATH.

Functions

func JournalRemoteCmdPath

func JournalRemoteCmdPath() (string, error)

JournalRemoteCmdPath searches for the systemd-journal-remote command in well-known paths and the directories named in the $PATH environment variable.

Types

type Sender

type Sender struct {
	CmdName    string
	OutputPath string

	// Clock for timestamping sent messages.
	Clock clock.Clock
	// Whether to assign the event's realtime timestamp to the time
	// specified by the SYSLOG_TIMESTAMP variable value. This is roughly
	// analogous to journald receiving the event and assigning it a
	// timestamp in zero time after the SYSLOG_TIMESTAMP value was set,
	// which is higly unrealistic in practice.
	AssignEventTimestampFromSyslogTimestamp bool
}

Sender fakes github.com/coreos/go-systemd/v22/journal.Send, writing journal entries to an arbitrary journal file without depending on a running journald process.

func New

func New(outpath string) (*Sender, error)

New constructs a new Sender which will write journal entries to outpath. The file name must end in '.journal' and the directory must already exist. The journal file will be created if it does not exist. An existing journal file will be appended to.

func NewT

func NewT(t *testing.T, outpath string) *Sender

NewT is like New but will skip the test if the systemd-journal-remote command is not available.

func (*Sender) Send

func (s *Sender) Send(message string, priority journal.Priority, vars map[string]string) error

Send is a drop-in replacement for github.com/coreos/go-systemd/v22/journal.Send.

Jump to

Keyboard shortcuts

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