teststate

package
v0.0.0-...-0da26dc Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package teststate provides test-only implementation for state-specific interfaces.

Index

Constants

View Source
const (
	// Type is the type of an Item.
	Type = "test-type"
)

Variables

View Source
var (
	// Item1 is an Item with ID 1.
	Item1 = NewItem("1")
	// Item2 is an Item with ID 2.
	Item2 = NewItem("2")
)

Functions

This section is empty.

Types

type Item

type Item struct {
	// I is the item's ID.
	I string
	// S represents whether the Marshal operation on this object will be successful.
	S bool
}

Item implements persist.MarshallableItem and MarshallableQueueItem interfaces for testing.

func NewItem

func NewItem(id string) Item

NewItem creates a Item with success status.

func (Item) Compare

func (i Item) Compare(other queue.Item) int

Compare compares two items in a priority queue.

func (Item) ID

func (i Item) ID() (string, error)

ID returns the item's ID.

func (Item) Marshal

func (i Item) Marshal() ([]byte, error)

Marshal marshals item for persisting.

type ItemSyncer

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

ItemSyncer implements the persist.ItemSyncer interface using a map. It tracks the LoadByID requests made to the syncer in the form of an internal `reqs` map for testing purposes.

func NewItemSyncer

func NewItemSyncer() *ItemSyncer

NewItemSyncer initializes the ItemSyncer.

func NewItemSyncerWithDelete

func NewItemSyncerWithDelete(delete bool) *ItemSyncer

NewItemSyncerWithDelete initializes the ItemSyncer with a value for whether to delete items or not.

func (*ItemSyncer) Count

func (s *ItemSyncer) Count() int

Count returns number of elements in the syncer for testing.

func (*ItemSyncer) CountDeletes

func (s *ItemSyncer) CountDeletes() int

CountDeletes returns the number of deletions requested.

func (*ItemSyncer) Delete

func (s *ItemSyncer) Delete(item persist.MarshallableItem) error

Delete deletes an item from the map.

func (*ItemSyncer) LoadAll

func (s *ItemSyncer) LoadAll() ([]persist.MarshallableItem, error)

LoadAll returns a slice of all the items in the map, sorted by id.

func (*ItemSyncer) LoadByID

func (s *ItemSyncer) LoadByID(id string) (persist.MarshallableItem, error)

LoadByID returns an item in the map with the provided id, if it exists.

func (*ItemSyncer) WasRequested

func (s *ItemSyncer) WasRequested(id string) bool

WasRequested returns whether LoadByID was ever called with a specific id.

func (*ItemSyncer) Write

func (s *ItemSyncer) Write(item persist.MarshallableItem) error

Write writes an item to the map.

Jump to

Keyboard shortcuts

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