fake

package
v0.0.0-...-f7cdbce Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fake provides a fake client for testing. It implements the client.Client interface but saves all entries in memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a fake client that stores all pushed entries in memory.

func New

func New() *Client

New creates a new Client. It is safe to call concurrently from multiple goroutines.

func (*Client) AssertEntries

func (client *Client) AssertEntries(t *testing.T, expected []client.Entry) bool

AssertEntries asserts that the Client has the given entries. It handles the locking of the Client for reading and unlocking it after the assertion. It is safe to call concurrently from multiple goroutines.

The entries are compared so that the timestamps are within a second of this function being called and all other fields are equal.

Like the testify/assert package, this function returns true if the assertion is successful.

func (*Client) Close

func (client *Client) Close()

Close unlocks the Client for reading. Note that if there are multiple open read locks due to Entries being called multiple times, Close will only release one of them. Each call to Entries should therefore be followed by a call to Close. It is safe to call concurrently from multiple goroutines.

func (*Client) Entries

func (client *Client) Entries() []client.Entry

Entries returns all entries that have been pushed to the Client. Entries should not be modified by the caller. It locks the Client for reading, so new entries cannot be pushed to the Client until after Close is called. It is safe to call concurrently from multiple goroutines.

func (*Client) Push

func (client *Client) Push(entry client.Entry) error

Push pushes the given entry to the Client. It is safe to call concurrently from multiple goroutines.

Jump to

Keyboard shortcuts

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