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 ¶
- type Cache
- type Coordinator
- func (c *Coordinator) PleasePull(_ context.Context, peer ifaces.NodeID, _, _ string, _ ifaces.OriginRefKind, ...) ([]ifaces.PleasePullOutcome, error)
- func (c *Coordinator) ProgramIntent(peer ifaces.NodeID, d digest.Digest, intent ifaces.PullIntent)
- func (c *Coordinator) ProgramPleasePull(peer ifaces.NodeID, d digest.Digest, outcome ifaces.PleasePullOutcome)
- func (c *Coordinator) PullIntentQuery(_ context.Context, peer ifaces.NodeID, d digest.Digest) (ifaces.PullIntent, error)
- type DHT
- func (d *DHT) FindProviders(_ context.Context, dg digest.Digest) ([]ifaces.Provider, error)
- func (d *DHT) Health() float64
- func (d *DHT) Inject(dg digest.Digest, providers ...ifaces.Provider)
- func (d *DHT) Provide(_ context.Context, dg digest.Digest) error
- func (d *DHT) ProvideCount(dg digest.Digest) int
- func (d *DHT) SetFindProvidersError(err error)
- func (d *DHT) SetHealth(score float64)
- func (d *DHT) Withdraw(_ context.Context, dg digest.Digest) error
- func (d *DHT) WithdrawCount(dg digest.Digest) int
- type Members
- type OriginPuller
- func (o *OriginPuller) Head(_ context.Context, ref ifaces.OriginRef) (int64, string, error)
- func (o *OriginPuller) HeadCount(d digest.Digest) int
- func (o *OriginPuller) Pull(_ context.Context, ref ifaces.OriginRef) (io.ReadCloser, int64, error)
- func (o *OriginPuller) PullCount(d digest.Digest) int
- func (o *OriginPuller) Put(d digest.Digest, body []byte)
- type PeerDialer
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.
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 (*DHT) FindProviders ¶
func (*DHT) ProvideCount ¶
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 ¶
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.
type Members ¶
type Members struct {
// contains filtered or unexported fields
}
Members is an ifaces.Members backed by a static slice.
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 (o *OriginPuller) Pull(_ context.Context, ref ifaces.OriginRef) (io.ReadCloser, int64, error)
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)