Documentation
¶
Overview ¶
Package testsupport provides shared test helpers used across multiple packages. It avoids duplicating mock implementations in each test file.
Index ¶
- Constants
- Variables
- func DisableThroughLadder(t testing.TB, b *providergate.Binding, id subflux.ProviderID, ...) []string
- func MediaPresence(roots ...string) *mediapresence.Checker
- func MediaWriter() *mediawrite.Writer
- func ProviderGateBinding() *providergate.Binding
- func RefChecksum() uint32
- func RefTotalEpisodes() int
- func SwapDefaultLogger(t testing.TB, l *slog.Logger)
- type AuthRecordStore
- func (s *AuthRecordStore) DeleteProviderAuthRecord(_ context.Context, id subflux.ProviderID) error
- func (s *AuthRecordStore) ProviderAuthRecords(context.Context) ([]subflux.ProviderAuthRecord, error)
- func (s *AuthRecordStore) PutProviderAuthRecord(_ context.Context, rec *subflux.ProviderAuthRecord) error
- func (s *AuthRecordStore) Record(id subflux.ProviderID) subflux.ProviderAuthRecord
- type NopAlerts
- type NopGateMetrics
- func (NopGateMetrics) DeleteProviderDisabled(subflux.ProviderID)
- func (NopGateMetrics) IncProviderAuthFailure(subflux.ProviderID)
- func (NopGateMetrics) IncProviderRateLimited(subflux.ProviderID, providergate.Op)
- func (NopGateMetrics) SetProviderDisabled(subflux.ProviderID, bool)
- func (NopGateMetrics) SetProviderSettingRejected(subflux.ProviderID, string, bool)
- type NopMediaMetrics
- type NopPresenceMetrics
- type NopStore
- func (*NopStore) BackedOffProviders(context.Context, subflux.MediaType, string, string, int) ([]subflux.ProviderID, error)
- func (*NopStore) BackoffByPrefix(context.Context, subflux.MediaType, string) ([]subflux.BackoffEntry, error)
- func (*NopStore) BackoffItems(context.Context) ([]subflux.BackoffEntry, error)
- func (*NopStore) BackupInto(context.Context, string) error
- func (*NopStore) CleanupDrift(context.Context, subflux.ConfigDrift) error
- func (*NopStore) ClearManualLock(context.Context, subflux.ManualLockKey) error
- func (*NopStore) ClearScanCycleStart(context.Context) error
- func (*NopStore) CurrentScore(context.Context, subflux.MediaType, string, string, subflux.Variant) (score int, at time.Time, found bool, _ error)
- func (*NopStore) DeleteStateByPaths(context.Context, []string) (subflux.CleanupResult, error)
- func (*NopStore) DeleteSubtitleFile(context.Context, subflux.MediaType, string, string, subflux.Variant, ...) error
- func (*NopStore) DownloadedRefs(context.Context, subflux.MediaType, string, string) ([]subflux.DownloadedRef, error)
- func (*NopStore) HistoryMediaIDs(context.Context, subflux.MediaType, string) ([]string, error)
- func (*NopStore) IsManuallyLocked(context.Context, subflux.ManualLockKey) (bool, error)
- func (*NopStore) LastScanTime(context.Context) (string, error)
- func (*NopStore) ManualLocks(context.Context) ([]subflux.ManualLockEntry, error)
- func (*NopStore) ManualSubtitlePaths(context.Context, subflux.ManualLockKey) ([]string, error)
- func (*NopStore) NextManualNumber(context.Context, subflux.ManualLockKey) int
- func (*NopStore) PollTimestamp(context.Context, subflux.PollKey) (time.Time, error)
- func (*NopStore) RecentlyScanned(context.Context, time.Time) (map[string]bool, error)
- func (*NopStore) ReconcileState(context.Context, func(context.Context, string) (bool, error), ...) (subflux.ReconcileResult, error)
- func (*NopStore) RecordNoResult(context.Context, subflux.MediaType, string, string, subflux.ProviderID, ...) error
- func (*NopStore) RecordScanState(context.Context, *subflux.ScanRecord) error
- func (*NopStore) RecordSubtitleFiles(context.Context, subflux.MediaType, string, []subflux.SubtitleFile) (bool, error)
- func (*NopStore) SaveDownload(context.Context, *subflux.DownloadRecord) error
- func (*NopStore) ScanCycleStart(context.Context) (time.Time, error)
- func (*NopStore) ScanStates(context.Context, subflux.MediaType, string) ([]subflux.ScanStateRow, error)
- func (*NopStore) SetPollTimestamp(context.Context, subflux.PollKey, time.Time) error
- func (*NopStore) SetScanCycleStart(context.Context, time.Time) error
- func (*NopStore) SetSyncOffset(context.Context, string, int64) error
- func (*NopStore) State(context.Context, *subflux.StateQuery) (subflux.StatePage, error)
- func (*NopStore) Stats(context.Context) (downloads, backoffs int, _ error)
- func (*NopStore) StoreFileStats() (fileBytes, freelistBytes int64)
- func (*NopStore) SubtitleFiles(context.Context, subflux.MediaType, string) ([]subflux.SubtitleEntry, error)
- func (*NopStore) SyncOffset(context.Context, string) (int64, error)
- func (*NopStore) TotalSubtitleFiles(context.Context) (int, error)
- func (*NopStore) UpsertSubtitleFile(context.Context, subflux.MediaType, string, *subflux.SubtitleFile) error
- type RefMovie
- type RefSeries
Constants ¶
const ( RefSeriesCount = 500 RefMovieCount = 4360 )
Reference-library scale (design: 500 series / ~10k episodes / 4,360 movies).
Variables ¶
var ( RefAudioLangs = [5]string{"en", "ja", "fr", "de", "es"} RefAudioNames = [5]string{"English", "Japanese", "French", "German", "Spanish"} )
RefAudioLangs is the audio-language CODE table AudioIdx indexes into, and RefAudioNames the matching arr language-NAME table (same index). The TS mirror carries the code table; the two must stay index-aligned — the coveragehandlers stress test pins the correspondence through the real name→code mapping.
Functions ¶
func DisableThroughLadder ¶ added in v0.6.6
func DisableThroughLadder(t testing.TB, b *providergate.Binding, id subflux.ProviderID, op providergate.Op, call func() error, advance func(time.Duration), ) []string
DisableThroughLadder runs call through the binding's admission once per rung of the credential ladder, observing each failure and moving the clock past the rung's pause with advance, and returns every error text call produced. It fails the test when the binding refuses a call before the disable or when call succeeds.
func MediaPresence ¶ added in v0.6.6
func MediaPresence(roots ...string) *mediapresence.Checker
MediaPresence returns a checker bound to roots with no-op reporting.
func MediaWriter ¶ added in v0.6.6
func MediaWriter() *mediawrite.Writer
MediaWriter returns an unbound writer with the default atomicfile write and no-op reporting: saves land on disk, a folder fault blocks its folder, and Preflight probes nothing until a Bind.
func ProviderGateBinding ¶ added in v0.6.6
func ProviderGateBinding() *providergate.Binding
ProviderGateBinding returns a binding over a memory-only gate that was never activated, so every provider starts admitted and the ladder still applies.
func RefChecksum ¶ added in v0.5.0
func RefChecksum() uint32
RefChecksum is the FNV-1a-style fold over every drawn field of every item, the cross-language drift detector: both sync tests pin its exact value.
func RefTotalEpisodes ¶ added in v0.5.0
func RefTotalEpisodes() int
RefTotalEpisodes folds the deterministic episode total (~10k by construction; the exact value is pinned by both sync tests).
func SwapDefaultLogger ¶ added in v0.5.19
SwapDefaultLogger installs l as slog's default for the rest of the test and restores slog's default, log.Writer and log.Flags on cleanup.
All three matter: slog.SetDefault also aims the standard log package at the installed handler and SKIPS that redirect for slog's own defaultHandler (which would deadlock on log's mutex), so reinstalling the previous logger cannot undo it, and slog's stock handler emits through log.Output. Restore slog first, or a previous non-defaultHandler logger re-runs the redirect.
Types ¶
type AuthRecordStore ¶ added in v0.6.6
type AuthRecordStore struct {
// contains filtered or unexported fields
}
AuthRecordStore is an in-memory providergate.Store that keeps the last record written for each provider.
func NewAuthRecordStore ¶ added in v0.6.6
func NewAuthRecordStore() *AuthRecordStore
NewAuthRecordStore returns an empty store.
func (*AuthRecordStore) DeleteProviderAuthRecord ¶ added in v0.6.6
func (s *AuthRecordStore) DeleteProviderAuthRecord(_ context.Context, id subflux.ProviderID) error
DeleteProviderAuthRecord drops the provider's record.
func (*AuthRecordStore) ProviderAuthRecords ¶ added in v0.6.6
func (s *AuthRecordStore) ProviderAuthRecords(context.Context) ([]subflux.ProviderAuthRecord, error)
ProviderAuthRecords returns nothing, so a gate opened over the store starts with every provider admitted.
func (*AuthRecordStore) PutProviderAuthRecord ¶ added in v0.6.6
func (s *AuthRecordStore) PutProviderAuthRecord(_ context.Context, rec *subflux.ProviderAuthRecord) error
PutProviderAuthRecord keeps rec as the provider's record.
func (*AuthRecordStore) Record ¶ added in v0.6.6
func (s *AuthRecordStore) Record(id subflux.ProviderID) subflux.ProviderAuthRecord
Record returns the provider's last written record.
type NopAlerts ¶ added in v0.6.6
type NopAlerts struct{}
NopAlerts is a mediawrite.Alerts that holds no alert.
func (NopAlerts) DismissBySource ¶ added in v0.6.6
DismissBySource records nothing.
func (NopAlerts) HasUndismissed ¶ added in v0.6.6
HasUndismissed reports false.
func (NopAlerts) RecordPersistent ¶ added in v0.6.6
RecordPersistent records nothing.
type NopGateMetrics ¶ added in v0.6.6
type NopGateMetrics struct{}
NopGateMetrics is a providergate.Metrics that records nothing.
func (NopGateMetrics) DeleteProviderDisabled ¶ added in v0.6.6
func (NopGateMetrics) DeleteProviderDisabled(subflux.ProviderID)
DeleteProviderDisabled records nothing.
func (NopGateMetrics) IncProviderAuthFailure ¶ added in v0.6.6
func (NopGateMetrics) IncProviderAuthFailure(subflux.ProviderID)
IncProviderAuthFailure records nothing.
func (NopGateMetrics) IncProviderRateLimited ¶ added in v0.6.6
func (NopGateMetrics) IncProviderRateLimited(subflux.ProviderID, providergate.Op)
IncProviderRateLimited records nothing.
func (NopGateMetrics) SetProviderDisabled ¶ added in v0.6.6
func (NopGateMetrics) SetProviderDisabled(subflux.ProviderID, bool)
SetProviderDisabled records nothing.
func (NopGateMetrics) SetProviderSettingRejected ¶ added in v0.6.6
func (NopGateMetrics) SetProviderSettingRejected(subflux.ProviderID, string, bool)
SetProviderSettingRejected records nothing.
type NopMediaMetrics ¶ added in v0.6.6
type NopMediaMetrics struct{}
NopMediaMetrics is a mediawrite.Metrics that records nothing.
func (NopMediaMetrics) DeleteMediaRoot ¶ added in v0.6.6
func (NopMediaMetrics) DeleteMediaRoot(string)
DeleteMediaRoot records nothing.
func (NopMediaMetrics) IncSubtitleWriteError ¶ added in v0.6.6
func (NopMediaMetrics) IncSubtitleWriteError()
IncSubtitleWriteError records nothing.
func (NopMediaMetrics) SetMediaRootUnwritable ¶ added in v0.6.6
func (NopMediaMetrics) SetMediaRootUnwritable(string, bool)
SetMediaRootUnwritable records nothing.
type NopPresenceMetrics ¶ added in v0.6.6
type NopPresenceMetrics struct{}
NopPresenceMetrics is a mediapresence.Metrics that records nothing.
func (NopPresenceMetrics) DeleteMediaRootUnavailable ¶ added in v0.6.6
func (NopPresenceMetrics) DeleteMediaRootUnavailable(string)
DeleteMediaRootUnavailable records nothing.
func (NopPresenceMetrics) SetMediaRootUnavailable ¶ added in v0.6.6
func (NopPresenceMetrics) SetMediaRootUnavailable(string, bool)
SetMediaRootUnavailable records nothing.
type NopStore ¶
type NopStore struct{}
NopStore is the shared store fake: every method returns a zero value and nothing is persisted. Embed it in a test-specific mock and override only the methods that test exercises.
Its WIDTH is now derived, not declared. There is no store interface for it to be exhaustive against any more, so what it must implement is exactly the union of the narrow interfaces the eight packages that use it install it as (search.Store, scanning.ScanStore, scheduler.Store, queryhandlers.QueryStore, synchandlers.SyncStore, filehandlers.FileStore, coveragehandlers.CoverageStore, manualops.DownloadStore, polling.PollerStore, resolve.FileStore, coverage.FileReader, and server.Store, which is the union of most of those). nopstore_test.go states that union in one anonymous interface, so a consumer that adds a method fails there with a readable message rather than at a dozen install sites.
Two methods went with the composite because nothing reaches them through an interface: Close (main.go calls it on the concrete *boltstore.DB) and ManualDownloadCount (boltstore's own NextManualNumber fallback and its tests are the only callers). A sibling panicStore used to shadow all 36 methods so that a new one would announce itself; every one of them was overridden here, so it was 159 lines that changed no behaviour, and it is gone.
func (*NopStore) BackedOffProviders ¶
func (*NopStore) BackedOffProviders(context.Context, subflux.MediaType, string, string, int) ([]subflux.ProviderID, error)
BackedOffProviders returns providers currently in backoff for the given media item.
func (*NopStore) BackoffByPrefix ¶ added in v0.4.0
func (*NopStore) BackoffByPrefix(context.Context, subflux.MediaType, string) ([]subflux.BackoffEntry, error)
BackoffByPrefix returns backoff entries matching the given media type and ID prefix.
func (*NopStore) BackoffItems ¶ added in v0.4.0
BackoffItems returns all items currently in adaptive search backoff.
func (*NopStore) BackupInto ¶ added in v0.4.0
BackupInto reports success without writing a snapshot.
func (*NopStore) CleanupDrift ¶
CleanupDrift removes search_attempts entries for providers/languages that are no longer in the active configuration.
func (*NopStore) ClearManualLock ¶
ClearManualLock removes the manual download lock on the key's quad.
func (*NopStore) ClearScanCycleStart ¶ added in v0.1.148
ClearScanCycleStart is a no-op.
func (*NopStore) CurrentScore ¶
func (*NopStore) CurrentScore(context.Context, subflux.MediaType, string, string, subflux.Variant) (score int, at time.Time, found bool, _ error)
CurrentScore returns the current subtitle score for a media item and language.
func (*NopStore) DeleteStateByPaths ¶
DeleteStateByPaths removes all state records associated with the given video paths.
func (*NopStore) DeleteSubtitleFile ¶
func (*NopStore) DeleteSubtitleFile(context.Context, subflux.MediaType, string, string, subflux.Variant, subflux.SubtitleSource, string) error
DeleteSubtitleFile removes a subtitle file record for a media item.
func (*NopStore) DownloadedRefs ¶
func (*NopStore) DownloadedRefs(context.Context, subflux.MediaType, string, string) ([]subflux.DownloadedRef, error)
DownloadedRefs returns the previously downloaded subtitle references for a media item.
func (*NopStore) HistoryMediaIDs ¶
HistoryMediaIDs returns distinct media IDs with download history for the given type and language.
func (*NopStore) IsManuallyLocked ¶
IsManuallyLocked reports whether the key's quad has a manual download lock.
func (*NopStore) LastScanTime ¶
LastScanTime returns the formatted timestamp of the most recent scan completion.
func (*NopStore) ManualLocks ¶ added in v0.4.0
ManualLocks returns all active manual download locks.
func (*NopStore) ManualSubtitlePaths ¶
ManualSubtitlePaths returns paths of manually downloaded subtitle files on the key's quad.
func (*NopStore) NextManualNumber ¶
NextManualNumber returns the next sequential number for a manual subtitle file.
func (*NopStore) PollTimestamp ¶ added in v0.4.0
PollTimestamp returns the last poll timestamp for the given poll key.
func (*NopStore) RecentlyScanned ¶
RecentlyScanned returns the set of media IDs scanned after the given cutoff time.
func (*NopStore) ReconcileState ¶
func (*NopStore) ReconcileState(context.Context, func(context.Context, string) (bool, error), func(string) (string, bool)) (subflux.ReconcileResult, error)
ReconcileState performs the three-way filesystem reconciliation pass.
func (*NopStore) RecordNoResult ¶
func (*NopStore) RecordNoResult(context.Context, subflux.MediaType, string, string, subflux.ProviderID, subflux.BackoffParams) error
RecordNoResult records a provider returning no result for a media item, updating backoff state.
func (*NopStore) RecordScanState ¶
RecordScanState records the scan timestamp and metadata for a media item.
func (*NopStore) RecordSubtitleFiles ¶
func (*NopStore) RecordSubtitleFiles(context.Context, subflux.MediaType, string, []subflux.SubtitleFile) (bool, error)
RecordSubtitleFiles records the full set of subtitle files for a media item.
func (*NopStore) SaveDownload ¶
SaveDownload records or updates a subtitle download record.
func (*NopStore) ScanCycleStart ¶ added in v0.1.148
ScanCycleStart returns the zero time (no cycle mark stored).
func (*NopStore) ScanStates ¶ added in v0.4.0
func (*NopStore) ScanStates(context.Context, subflux.MediaType, string) ([]subflux.ScanStateRow, error)
ScanStates returns scan state records for a media item prefix.
func (*NopStore) SetPollTimestamp ¶
SetPollTimestamp stores the poll timestamp for the given poll key.
func (*NopStore) SetScanCycleStart ¶ added in v0.1.148
SetScanCycleStart is a no-op.
func (*NopStore) SetSyncOffset ¶
SetSyncOffset stores the subtitle timing offset in milliseconds for a video path.
func (*NopStore) StoreFileStats ¶ added in v0.4.0
StoreFileStats reports an empty store.
func (*NopStore) SubtitleFiles ¶ added in v0.4.0
func (*NopStore) SubtitleFiles(context.Context, subflux.MediaType, string) ([]subflux.SubtitleEntry, error)
SubtitleFiles returns subtitle file records for a media item.
func (*NopStore) SyncOffset ¶ added in v0.4.0
SyncOffset returns the stored timing offset in milliseconds for a video path.
func (*NopStore) TotalSubtitleFiles ¶
TotalSubtitleFiles returns the total number of tracked subtitle file records.
type RefMovie ¶ added in v0.5.0
type RefMovie struct {
Title string
SceneName string
TmdbID int
ArrID int
Year int
HaveEN int
HaveFR int
EmbeddedTracks int
SceneIdx int
AudioIdx int
HasFR bool
}
RefMovie is one deterministic reference-library movie. Every reference movie is file-bearing (the shipped collections omit file-less rows, and the reference payload is the 4,360 rows that reach the wire).
func RefMovieItems ¶ added in v0.5.0
func RefMovieItems() []RefMovie
RefMovieItems generates the 4,360 reference movies.
type RefSeries ¶ added in v0.5.0
type RefSeries struct {
Title string
TvdbID int
ArrID int
Year int
Episodes int
EpisodesPerSeason int
Seasons int
HaveEN int
HaveFR int
AudioIdx int
HasFR bool
}
RefSeries is one deterministic reference-library series: the canonical per-item record both language sides derive their wire/DTO shapes from.
func RefSeriesItems ¶ added in v0.5.0
func RefSeriesItems() []RefSeries
RefSeriesItems generates the 500 reference series. Episode counts follow a long-tail bucket distribution (half short single-season shows, a few long-runners) tuned so the deterministic total lands near 10k.