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 RefChecksum() uint32
- func RefTotalEpisodes() int
- func SwapDefaultLogger(t testing.TB, l *slog.Logger)
- 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) (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.StateEntry, 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 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 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 ¶
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) State ¶ added in v0.4.0
func (*NopStore) State(context.Context, *subflux.StateQuery) ([]subflux.StateEntry, error)
State returns download state entries matching the query.
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.