testsupport

package
v0.8.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testsupport provides shared test helpers used across multiple packages. It avoids duplicating mock implementations in each test file.

Index

Constants

View Source
const (
	RefSeriesCount = 500
	RefMovieCount  = 4360
)

Reference-library scale (design: 500 series / ~10k episodes / 4,360 movies).

Variables

View Source
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

func SwapDefaultLogger(t testing.TB, l *slog.Logger)

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 (*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

Record returns the provider's last written record.

type NoDetector added in v0.7.0

type NoDetector struct{}

NoDetector is a track detector that finds no embedded tracks, for engines built by tests that do not exercise embedded detection.

func (NoDetector) DetectTracks added in v0.7.0

DetectTracks returns no tracks and no error.

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

func (NopAlerts) DismissBySource(string)

DismissBySource records nothing.

func (NopAlerts) HasUndismissed added in v0.6.6

func (NopAlerts) HasUndismissed(string) bool

HasUndismissed reports false.

func (NopAlerts) RecordPersistent added in v0.6.6

func (NopAlerts) RecordPersistent(string, string)

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

BackedOffProviders returns providers currently in backoff for the given media item.

func (*NopStore) BackoffByPrefix added in v0.4.0

BackoffByPrefix returns backoff entries matching the given media type and ID prefix.

func (*NopStore) BackoffItems added in v0.4.0

func (*NopStore) BackoffItems(context.Context) ([]subflux.BackoffEntry, error)

BackoffItems returns all items currently in adaptive search backoff.

func (*NopStore) BackupInto added in v0.4.0

func (*NopStore) BackupInto(context.Context, string) error

BackupInto reports success without writing a snapshot.

func (*NopStore) CleanupDrift

func (*NopStore) CleanupDrift(context.Context, subflux.ConfigDrift) error

CleanupDrift removes search_attempts entries for providers/languages that are no longer in the active configuration.

func (*NopStore) ClearManualLock

func (*NopStore) ClearManualLock(context.Context, subflux.ManualLockKey) error

ClearManualLock removes the manual download lock on the key's quad.

func (*NopStore) ClearScanCycleStart added in v0.1.148

func (*NopStore) ClearScanCycleStart(context.Context) error

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

func (*NopStore) DeleteStateByPaths(context.Context, []string) (subflux.CleanupResult, error)

DeleteStateByPaths removes all state records associated with the given video paths.

func (*NopStore) DeleteSubtitleFile

DeleteSubtitleFile removes a subtitle file record for a media item.

func (*NopStore) DownloadedRefs

DownloadedRefs returns the previously downloaded subtitle references for a media item.

func (*NopStore) HistoryMediaIDs

func (*NopStore) HistoryMediaIDs(context.Context, subflux.MediaType, string) ([]string, error)

HistoryMediaIDs returns distinct media IDs with download history for the given type and language.

func (*NopStore) IsManuallyLocked

func (*NopStore) IsManuallyLocked(context.Context, subflux.ManualLockKey) (bool, error)

IsManuallyLocked reports whether the key's quad has a manual download lock.

func (*NopStore) LastScanTime

func (*NopStore) LastScanTime(context.Context) (string, error)

LastScanTime returns the formatted timestamp of the most recent scan completion.

func (*NopStore) ManualLocks added in v0.4.0

func (*NopStore) ManualLocks(context.Context) ([]subflux.ManualLockEntry, error)

ManualLocks returns all active manual download locks.

func (*NopStore) ManualSubtitlePaths

func (*NopStore) ManualSubtitlePaths(context.Context, subflux.ManualLockKey) ([]string, error)

ManualSubtitlePaths returns paths of manually downloaded subtitle files on the key's quad.

func (*NopStore) NextManualNumber

func (*NopStore) NextManualNumber(context.Context, subflux.ManualLockKey) int

NextManualNumber returns the next sequential number for a manual subtitle file.

func (*NopStore) PollTimestamp added in v0.4.0

func (*NopStore) PollTimestamp(context.Context, subflux.PollKey) (time.Time, error)

PollTimestamp returns the last poll timestamp for the given poll key.

func (*NopStore) RecentlyScanned

func (*NopStore) RecentlyScanned(context.Context, time.Time) (map[string]bool, error)

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

RecordNoResult records a provider returning no result for a media item, updating backoff state.

func (*NopStore) RecordScanState

func (*NopStore) RecordScanState(context.Context, *subflux.ScanRecord) error

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

func (*NopStore) ScanCycleStart(context.Context) (time.Time, error)

ScanCycleStart returns the zero time (no cycle mark stored).

func (*NopStore) ScanStates added in v0.4.0

ScanStates returns scan state records for a media item prefix.

func (*NopStore) SetPollTimestamp

func (*NopStore) SetPollTimestamp(context.Context, subflux.PollKey, time.Time) error

SetPollTimestamp stores the poll timestamp for the given poll key.

func (*NopStore) SetScanCycleStart added in v0.1.148

func (*NopStore) SetScanCycleStart(context.Context, time.Time) error

SetScanCycleStart is a no-op.

func (*NopStore) SetSyncOffset

func (*NopStore) SetSyncOffset(context.Context, string, int64) error

SetSyncOffset stores the subtitle timing offset in milliseconds for a video path.

func (*NopStore) State added in v0.4.0

State returns an empty page of download state entries.

func (*NopStore) Stats

func (*NopStore) Stats(context.Context) (downloads, backoffs int, _ error)

Stats returns aggregate counts for downloads and active backoff entries.

func (*NopStore) StoreFileStats added in v0.4.0

func (*NopStore) StoreFileStats() (fileBytes, freelistBytes int64)

StoreFileStats reports an empty store.

func (*NopStore) SubtitleFiles added in v0.4.0

SubtitleFiles returns subtitle file records for a media item.

func (*NopStore) SyncOffset added in v0.4.0

func (*NopStore) SyncOffset(context.Context, string) (int64, error)

SyncOffset returns the stored timing offset in milliseconds for a video path.

func (*NopStore) TotalSubtitleFiles

func (*NopStore) TotalSubtitleFiles(context.Context) (int, error)

TotalSubtitleFiles returns the total number of tracked subtitle file records.

func (*NopStore) UpsertSubtitleFile

UpsertSubtitleFile inserts or updates a single subtitle file record.

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.

Jump to

Keyboard shortcuts

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