fakes

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package fakes provides in-memory implementations of the ifaces interfaces for unit and integration tests. They are intentionally simple and exposed at package scope so test code in any package can wire up a complete agent without touching libp2p, Kubernetes, or the filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is an in-memory ifaces.LocalContentStore. Safe for concurrent use.

func NewCache

func NewCache() *Cache

func (*Cache) Has

func (c *Cache) Has(_ context.Context, d digest.Digest) (bool, error)

func (*Cache) Open

func (*Cache) Put

func (c *Cache) Put(d digest.Digest, body []byte)

Put injects a pre-verified entry directly. Intended for test setup.

func (*Cache) Writer

type Coordinator

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

Coordinator is an in-memory ifaces.Coordinator. Per-peer responses are programmed via Program.

func NewCoordinator

func NewCoordinator() *Coordinator

func (*Coordinator) PleasePull

func (c *Coordinator) PleasePull(_ context.Context, peer ifaces.NodeID, _, _ string, _ ifaces.OriginRefKind, digests []digest.Digest) ([]ifaces.PleasePullOutcome, error)

func (*Coordinator) ProgramIntent

func (c *Coordinator) ProgramIntent(peer ifaces.NodeID, d digest.Digest, intent ifaces.PullIntent)

ProgramIntent sets the canned PullIntent response for (peer, d).

func (*Coordinator) ProgramPleasePull

func (c *Coordinator) ProgramPleasePull(peer ifaces.NodeID, d digest.Digest, outcome ifaces.PleasePullOutcome)

ProgramPleasePull sets the canned per-digest outcome for (peer, d). Tests programming a batched please_pull MUST seed each digest.

func (*Coordinator) PullIntentQuery

func (c *Coordinator) PullIntentQuery(_ context.Context, peer ifaces.NodeID, d digest.Digest) (ifaces.PullIntent, error)

type DHT

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

DHT is an in-memory ifaces.DHT. Provides and FindProviders share a digest->providers map, and Health returns a configurable score.

func NewDHT

func NewDHT() *DHT

func (*DHT) FindProviders

func (d *DHT) FindProviders(_ context.Context, dg digest.Digest) ([]ifaces.Provider, error)

func (*DHT) Health

func (d *DHT) Health() float64

func (*DHT) Inject

func (d *DHT) Inject(dg digest.Digest, providers ...ifaces.Provider)

Inject seeds the provider list for a digest.

func (*DHT) Provide

func (d *DHT) Provide(_ context.Context, dg digest.Digest) error

func (*DHT) ProvideCount

func (d *DHT) ProvideCount(dg digest.Digest) int

ProvideCount returns the number of times Provide was called for dg. Used by tests that assert the-step-7 re-advertise path fires.

func (*DHT) SetFindProvidersError

func (d *DHT) SetFindProvidersError(err error)

SetFindProvidersError programs the next (and all subsequent) FindProviders calls to return err. Pass nil to clear. Useful for regression tests that exercise the DHT-error fallback path.

func (*DHT) SetHealth

func (d *DHT) SetHealth(score float64)

func (*DHT) Withdraw

func (d *DHT) Withdraw(_ context.Context, dg digest.Digest) error

Withdraw implements ifaces.DHT. Tracks per-digest call counts so tests of the advertiser's eviction path can assert the hint fires exactly once per withdrawn digest.

func (*DHT) WithdrawCount

func (d *DHT) WithdrawCount(dg digest.Digest) int

WithdrawCount returns the number of times Withdraw was called for dg.

type Members

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

Members is an ifaces.Members backed by a static slice.

func NewMembers

func NewMembers(self ifaces.NodeID, nodes ...ifaces.Node) *Members

func (*Members) Self

func (m *Members) Self() ifaces.NodeID

func (*Members) Snapshot

func (m *Members) Snapshot() []ifaces.Node

func (*Members) WaitForSync

func (m *Members) WaitForSync(_ context.Context) error

type OriginPuller

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

OriginPuller is an in-memory ifaces.OriginPuller. Entries seeded via Put are served verbatim; unset references return *ifaces.OriginError with FailureNotFound.

func NewOriginPuller

func NewOriginPuller() *OriginPuller

func (*OriginPuller) Head

Head implements ifaces.OriginPuller. The fake returns the same size it would have served from Pull (so callers that HEAD-then-GET see a consistent Content-Length) without consuming a Pull slot. The fake returns an empty content-type - tests that care about the HEAD-time media type should use a custom origin double.

func (*OriginPuller) HeadCount

func (o *OriginPuller) HeadCount(d digest.Digest) int

HeadCount returns the number of Head invocations seen for d.

func (*OriginPuller) Pull

func (*OriginPuller) PullCount

func (o *OriginPuller) PullCount(d digest.Digest) int

PullCount returns the number of Pull invocations seen for d.

func (*OriginPuller) Put

func (o *OriginPuller) Put(d digest.Digest, body []byte)

type PeerDialer

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

PeerDialer routes FetchFromPeer to a per-address ifaces.LocalContentStore. Tests wire each "peer's" local cache into this map.

func NewPeerDialer

func NewPeerDialer() *PeerDialer

func (*PeerDialer) FailOn

func (p *PeerDialer) FailOn(addr string, err error)

FailOn forces FetchFromPeer to return err for any request to addr. Used to model unreachable peers in tests.

func (*PeerDialer) FetchFromPeer

func (p *PeerDialer) FetchFromPeer(ctx context.Context, addr string, ref ifaces.OriginRef) (io.ReadCloser, int64, error)

func (*PeerDialer) Register

func (p *PeerDialer) Register(addr string, cache ifaces.LocalContentStore)

Jump to

Keyboard shortcuts

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