Documentation
¶
Overview ¶
Package fakeapi provides shared concurrency-safe test fakes for the interfaces in internal/api. Consumes no I/O. Import from _test.go files only — the package name carries no internal build tag, but callers across internal/{sync,scheduler,notify,users} tests previously declared three near-identical fakeCache types; this package consolidates them into one honest implementation.
Index ¶
- func RunCacheContract(t *testing.T, c api.Cache)
- type Cache
- func (c *Cache) CheckAndMark(key string) bool
- func (c *Cache) LastSchedulerRun() time.Time
- func (c *Cache) LearnLanguageProfile(userID, audioLang, subtitleLang string)
- func (c *Cache) MarkProcessed(key string)
- func (c *Cache) Processed() []string
- func (c *Cache) SetLastSchedulerRun(t time.Time)
- func (c *Cache) SetUserTokens(tokens map[string]string)
- func (c *Cache) SubtitleLangForAudio(userID, audioLang string) (string, bool)
- func (c *Cache) UserTokens() map[string]string
- func (c *Cache) WasRecentlyProcessed(key string) bool
- type Plex
- func (f *Plex) CallNames() []string
- func (f *Plex) DisableSubtitles(_ context.Context, _ int) error
- func (f *Plex) Episode(_ context.Context, key plex.RatingKey) (*streams.Episode, error)
- func (f *Plex) History(_ context.Context, _ int64) ([]plex.HistoryItem, error)
- func (f *Plex) RecentlyAdded(_ context.Context, sectionKey plex.RatingKey, _ int64) ([]streams.Episode, error)
- func (f *Plex) SeasonEpisodes(_ context.Context, key plex.RatingKey) ([]streams.Episode, error)
- func (f *Plex) SetAudioStream(_ context.Context, _, _ int) error
- func (f *Plex) SetSubtitleStream(_ context.Context, _, _ int) error
- func (f *Plex) ShowEpisodes(_ context.Context, showRatingKey plex.RatingKey) ([]streams.Episode, error)
- func (f *Plex) ShowMetadata(_ context.Context, key plex.RatingKey) (*plex.Show, error)
- func (f *Plex) ShowSections(_ context.Context) ([]plex.Section, error)
- func (f *Plex) UserFromSession(_ context.Context, _ string) (userID, username string, err error)
- type Users
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a concurrency-safe in-memory implementation of api.Cache. Every accessor takes a short-held lock; consumers can share one Cache across goroutines without additional synchronization.
Beyond api.Cache, Cache exposes the Processed helper reader (NOT part of api.Cache) that tests use to inspect the fake's state after a run.
func NewCache ¶
func NewCache() *Cache
NewCache returns a ready-to-use zero-seeded Cache with the default recent-window of 5 minutes, matching internal/cache.Cache's WasRecentlyProcessed behavior.
func (*Cache) CheckAndMark ¶ added in v1.4.0
CheckAndMark atomically tests and sets the recent-processed window for key, mirroring internal/cache.Cache.CheckAndMark: it returns true and records the current time when key is outside the recent window, or false (leaving the existing timestamp intact) when it is inside. The check and the mark happen under a single lock acquisition so two concurrent callers cannot both observe "not processed" for the same key.
func (*Cache) LastSchedulerRun ¶
LastSchedulerRun returns the recorded last-run timestamp. Zero value indicates "never run".
func (*Cache) LearnLanguageProfile ¶
LearnLanguageProfile stores a user's audio→subtitle preference. Empty audioLang is ignored to match internal/cache.Cache.
func (*Cache) MarkProcessed ¶
MarkProcessed records the current time against the key.
func (*Cache) Processed ¶
Processed returns a deterministically-ordered copy of the processed keys. Useful for asserting "the sync pass marked exactly these episodes as processed" without relying on Go's map-iteration order.
func (*Cache) SetLastSchedulerRun ¶
SetLastSchedulerRun records the supplied timestamp.
func (*Cache) SetUserTokens ¶
SetUserTokens replaces the token map wholesale. Nil clears the map to an empty non-nil value.
func (*Cache) SubtitleLangForAudio ¶
SubtitleLangForAudio returns the learned subtitle language for the given audio language and user.
func (*Cache) UserTokens ¶
UserTokens returns a defensive copy of the userID → accessToken map.
func (*Cache) WasRecentlyProcessed ¶
WasRecentlyProcessed reports whether the key was MarkProcessed'd within the recent window.
type Plex ¶
type Plex struct {
UserFromSessionResult struct {
Err error
UserID string
Username string
}
EpisodeErr error
SetAudioErr error
SetSubtitleErr error
DisableErr error
ShowEpisodesErr error
ShowEpisodesByShow map[string][]streams.Episode
EpisodeByKey map[string]*streams.Episode
SeasonEpisodesByKey map[string][]streams.Episode
ShowMetadataByKey map[string]*plex.Show
RecentlyAddedBySec map[string][]streams.Episode
HistoryItems []plex.HistoryItem
Sections []plex.Section
Calls atomic.Int64
// contains filtered or unexported fields
}
Plex implements api.PlexReadWriter for tests. All methods are concurrency-safe. Fields are exported for direct test setup.
func (*Plex) DisableSubtitles ¶
DisableSubtitles records the call and returns DisableErr.
func (*Plex) Episode ¶
Episode returns the episode identified by key, or plex.ErrNotFound if EpisodeByKey has no matching entry.
func (*Plex) RecentlyAdded ¶
func (f *Plex) RecentlyAdded(_ context.Context, sectionKey plex.RatingKey, _ int64) ([]streams.Episode, error)
RecentlyAdded returns the recently-added episodes stored under sectionKey in RecentlyAddedBySec.
func (*Plex) SeasonEpisodes ¶
SeasonEpisodes returns all episodes stored under key in SeasonEpisodesByKey.
func (*Plex) SetAudioStream ¶
SetAudioStream records the call and returns SetAudioErr.
func (*Plex) SetSubtitleStream ¶
SetSubtitleStream records the call and returns SetSubtitleErr.
func (*Plex) ShowEpisodes ¶
func (f *Plex) ShowEpisodes(_ context.Context, showRatingKey plex.RatingKey) ([]streams.Episode, error)
ShowEpisodes returns all episodes stored under showRatingKey in ShowEpisodesByShow.
func (*Plex) ShowMetadata ¶
ShowMetadata returns the show metadata stored under key in ShowMetadataByKey, or plex.ErrNotFound if no entry exists.
func (*Plex) ShowSections ¶
ShowSections returns the Sections slice configured on the fake.