testutils

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFileExists

func AssertFileExists(t *testing.T, path string)

AssertFileExists checks if a file exists

func AssertFileNotExists

func AssertFileNotExists(t *testing.T, path string)

AssertFileNotExists checks if a file doesn't exist

func CreateInvalidTorrent

func CreateInvalidTorrent(t *testing.T, dir, name string) string

CreateInvalidTorrent creates an invalid torrent file (HTML) for testing

func CreateMagnetLink(t *testing.T, dir, name string) string

CreateMagnetLink creates a magnet link file for testing

func CreateRealTestTorrent

func CreateRealTestTorrent(t *testing.T, dir, name string) string

CreateRealTestTorrent creates a more realistic torrent file using bencode library

func CreateTestDataFile

func CreateTestDataFile(t *testing.T, dir, name string, size int64) string

CreateTestDataFile creates a test data file with specified size

func CreateTestTorrent

func CreateTestTorrent(t *testing.T, dir, name string) string

CreateTestTorrent creates a minimal valid torrent file for testing

func MockHTTPServer

func MockHTTPServer(t *testing.T, responses map[string]string) *httptest.Server

MockHTTPServer creates a mock HTTP server for testing

func MockYTDLPServer

func MockYTDLPServer(t *testing.T) *httptest.Server

MockYTDLPServer creates a mock server that responds like a video hosting service

func TempDir

func TempDir(t *testing.T) string

TempDir creates a temporary directory for testing

func TestConfig

func TestConfig(tempDir string) *config.Config

TestConfig creates a configuration suitable for testing

func TestDatabase

func TestDatabase(t *testing.T) database.Database

TestDatabase creates an in-memory SQLite database for testing

func WaitForCondition

func WaitForCondition(t *testing.T, condition func() bool, timeout time.Duration, message string)

WaitForCondition waits for a condition to be true or times out

Types

type DatabaseStub added in v1.4.3

type DatabaseStub struct{}

DatabaseStub implements database.Database with no-op methods. Embed it in test-specific mocks and override only the methods you need.

func (*DatabaseStub) AddMovie added in v1.4.3

func (*DatabaseStub) AddMovie(_ context.Context, _ string, _ int64, _, _ []string, _ int) (uint, error)

func (*DatabaseStub) AssignTemporaryPassword added in v1.4.3

func (*DatabaseStub) AssignTemporaryPassword(_ context.Context, _ string, _ int64) error

func (*DatabaseStub) ExtendTemporaryUser added in v1.4.3

func (*DatabaseStub) ExtendTemporaryUser(_ context.Context, _ int64, _ time.Time) error

func (*DatabaseStub) GenerateTemporaryPassword added in v1.4.3

func (*DatabaseStub) GenerateTemporaryPassword(_ context.Context, _ time.Duration) (string, error)

func (*DatabaseStub) GetFilesByMovieID added in v1.4.3

func (*DatabaseStub) GetFilesByMovieID(_ context.Context, _ uint) ([]database.MovieFile, error)

func (*DatabaseStub) GetIncompleteQBittorrentDownloads added in v1.6.0

func (*DatabaseStub) GetIncompleteQBittorrentDownloads(_ context.Context) ([]database.Movie, error)

func (*DatabaseStub) GetMovieByID added in v1.4.3

func (*DatabaseStub) GetMovieByID(_ context.Context, _ uint) (database.Movie, error)

func (*DatabaseStub) GetMovieList added in v1.4.3

func (*DatabaseStub) GetMovieList(_ context.Context) ([]database.Movie, error)

func (*DatabaseStub) GetTempFilesByMovieID added in v1.4.3

func (*DatabaseStub) GetTempFilesByMovieID(_ context.Context, _ uint) ([]database.MovieFile, error)

func (*DatabaseStub) GetUserByChatID added in v1.4.3

func (*DatabaseStub) GetUserByChatID(_ context.Context, _ int64) (database.User, error)

func (*DatabaseStub) GetUserRole added in v1.4.3

func (*DatabaseStub) GetUserRole(_ context.Context, _ int64) (database.UserRole, error)

func (*DatabaseStub) Init added in v1.4.3

func (*DatabaseStub) Init(_ *tmsconfig.Config) error

func (*DatabaseStub) IsUserAccessAllowed added in v1.4.3

func (*DatabaseStub) IsUserAccessAllowed(_ context.Context, _ int64) (allowed bool, role database.UserRole, err error)

func (*DatabaseStub) Login added in v1.4.3

func (*DatabaseStub) MovieExistsFiles added in v1.4.3

func (*DatabaseStub) MovieExistsFiles(_ context.Context, _ []string) (bool, error)

func (*DatabaseStub) MovieExistsId added in v1.4.3

func (*DatabaseStub) MovieExistsId(_ context.Context, _ uint) (bool, error)

func (*DatabaseStub) MovieExistsUploadedFile added in v1.4.3

func (*DatabaseStub) MovieExistsUploadedFile(_ context.Context, _ string) (bool, error)

func (*DatabaseStub) RemoveFilesByMovieID added in v1.4.3

func (*DatabaseStub) RemoveFilesByMovieID(_ context.Context, _ uint) error

func (*DatabaseStub) RemoveMovie added in v1.4.3

func (*DatabaseStub) RemoveMovie(_ context.Context, _ uint) error

func (*DatabaseStub) RemoveTempFilesByMovieID added in v1.4.3

func (*DatabaseStub) RemoveTempFilesByMovieID(_ context.Context, _ uint) error

func (*DatabaseStub) SetLoaded added in v1.4.3

func (*DatabaseStub) SetLoaded(_ context.Context, _ uint) error

func (*DatabaseStub) SetQBittorrentHash added in v1.6.0

func (*DatabaseStub) SetQBittorrentHash(_ context.Context, _ uint, _ string) error

func (*DatabaseStub) SetTvCompatibility added in v1.4.3

func (*DatabaseStub) SetTvCompatibility(_ context.Context, _ uint, _ string) error

func (*DatabaseStub) UpdateConversionPercentage added in v1.4.3

func (*DatabaseStub) UpdateConversionPercentage(_ context.Context, _ uint, _ int) error

func (*DatabaseStub) UpdateConversionStatus added in v1.4.3

func (*DatabaseStub) UpdateConversionStatus(_ context.Context, _ uint, _ string) error

func (*DatabaseStub) UpdateDownloadedPercentage added in v1.4.3

func (*DatabaseStub) UpdateDownloadedPercentage(_ context.Context, _ uint, _ int) error

func (*DatabaseStub) UpdateEpisodesProgress added in v1.4.3

func (*DatabaseStub) UpdateEpisodesProgress(_ context.Context, _ uint, _ int) error

func (*DatabaseStub) UpdateMovieName added in v1.5.5

func (*DatabaseStub) UpdateMovieName(_ context.Context, _ uint, _ string) error

type MockBot added in v1.4.3

type MockBot struct {
	SentMessages  []MockMessage
	SentDocuments []MockDocument

	// SendDocumentError, if set, is returned by SendDocument.
	SendDocumentError error
}

MockBot implements bot.Service for testing. SentMessages collects every message sent via SendMessage. SentDocuments collects every document sent via SendDocument.

func (*MockBot) AnswerCallbackQuery added in v1.4.3

func (*MockBot) AnswerCallbackQuery(_ tgbotapi.CallbackConfig)

func (*MockBot) ClearMessages added in v1.4.3

func (m *MockBot) ClearMessages()

ClearMessages resets the captured messages.

func (*MockBot) DeleteMessage added in v1.4.3

func (*MockBot) DeleteMessage(_ int64, _ int) error

func (*MockBot) DownloadFile added in v1.4.3

func (*MockBot) DownloadFile(_, _ string) error

func (*MockBot) EditMessageTextAndMarkup added in v1.4.3

func (*MockBot) EditMessageTextAndMarkup(_ int64, _ int, _ string, _ tgbotapi.InlineKeyboardMarkup) error

func (*MockBot) GetLastDocument added in v1.4.5

func (m *MockBot) GetLastDocument() *MockDocument

GetLastDocument returns the most recently sent document, or nil if none.

func (*MockBot) GetLastMessage added in v1.4.3

func (m *MockBot) GetLastMessage() *MockMessage

GetLastMessage returns the most recently sent message, or nil if none.

func (*MockBot) SaveFile added in v1.4.3

func (*MockBot) SaveFile(_ string, _ []byte) error

func (*MockBot) SendDocument added in v1.4.5

func (m *MockBot) SendDocument(chatID int64, fileName string, data []byte) error

func (*MockBot) SendMessage added in v1.4.3

func (m *MockBot) SendMessage(chatID int64, text string, keyboard any)

func (*MockBot) SendMessageReturningID added in v1.4.3

func (*MockBot) SendMessageReturningID(_ int64, _ string, _ any) (int, error)

type MockDocument added in v1.4.5

type MockDocument struct {
	ChatID   int64
	FileName string
	Data     []byte
}

MockDocument captures a single document sent by MockBot.

type MockDownloader added in v1.3.4

type MockDownloader struct {
	ShouldBlock  bool
	ShouldError  bool
	ErrorMessage string
	Title        string
	Files        []string
	TempFiles    []string
	FileSize     int64
	// EpisodesChan if set is returned from StartDownload; test can send completed episode counts (e.g. 1 for first_episode_ready).
	EpisodesChan chan int
	// TotalEps overrides TotalEpisodes() return value when > 0.
	TotalEps int
	// contains filtered or unexported fields
}

MockDownloader implements the downloader interface for testing. It provides methods for controlling download behavior in tests.

func (*MockDownloader) GetFileSize added in v1.3.4

func (m *MockDownloader) GetFileSize() (int64, error)

func (*MockDownloader) GetFiles added in v1.3.4

func (m *MockDownloader) GetFiles() (mainFiles, tempFiles []string, err error)

func (*MockDownloader) GetTitle added in v1.3.4

func (m *MockDownloader) GetTitle() (string, error)

func (*MockDownloader) StartDownload added in v1.3.4

func (m *MockDownloader) StartDownload(
	ctx context.Context,
) (progressChan chan float64, errChan chan error, episodesChan <-chan int, err error)

func (*MockDownloader) StopDownload added in v1.3.4

func (m *MockDownloader) StopDownload() error

func (*MockDownloader) StoppedManually added in v1.3.4

func (m *MockDownloader) StoppedManually() bool

func (*MockDownloader) TotalEpisodes added in v1.4.0

func (m *MockDownloader) TotalEpisodes() int

type MockMessage added in v1.4.3

type MockMessage struct {
	ChatID   int64
	Text     string
	Keyboard any
}

MockMessage captures a single message sent by MockBot.

type TestSQLiteDatabase

type TestSQLiteDatabase struct {
	// contains filtered or unexported fields
}

TestSQLiteDatabase is a test-specific implementation

func (*TestSQLiteDatabase) AddMovie

func (t *TestSQLiteDatabase) AddMovie(
	ctx context.Context,
	name string,
	fileSize int64,
	mainFiles, tempFiles []string,
	totalEpisodes int,
) (uint, error)

Implement all database interface methods by delegating to the real implementation

func (*TestSQLiteDatabase) AssignTemporaryPassword

func (*TestSQLiteDatabase) AssignTemporaryPassword(_ context.Context, _ string, _ int64) error

func (*TestSQLiteDatabase) ExtendTemporaryUser

func (*TestSQLiteDatabase) ExtendTemporaryUser(_ context.Context, _ int64, _ time.Time) error

func (*TestSQLiteDatabase) GenerateTemporaryPassword

func (*TestSQLiteDatabase) GenerateTemporaryPassword(_ context.Context, _ time.Duration) (string, error)

func (*TestSQLiteDatabase) GetFilesByMovieID

func (*TestSQLiteDatabase) GetFilesByMovieID(_ context.Context, _ uint) ([]database.MovieFile, error)

func (*TestSQLiteDatabase) GetIncompleteQBittorrentDownloads added in v1.6.0

func (*TestSQLiteDatabase) GetIncompleteQBittorrentDownloads(_ context.Context) ([]database.Movie, error)

func (*TestSQLiteDatabase) GetMovieByID

func (*TestSQLiteDatabase) GetMovieByID(_ context.Context, _ uint) (database.Movie, error)

func (*TestSQLiteDatabase) GetMovieList

func (*TestSQLiteDatabase) GetMovieList(_ context.Context) ([]database.Movie, error)

func (*TestSQLiteDatabase) GetTempFilesByMovieID

func (*TestSQLiteDatabase) GetTempFilesByMovieID(_ context.Context, _ uint) ([]database.MovieFile, error)

func (*TestSQLiteDatabase) GetUserByChatID

func (*TestSQLiteDatabase) GetUserByChatID(_ context.Context, _ int64) (database.User, error)

func (*TestSQLiteDatabase) GetUserRole

func (*TestSQLiteDatabase) Init

func (*TestSQLiteDatabase) IsUserAccessAllowed

func (*TestSQLiteDatabase) IsUserAccessAllowed(_ context.Context, _ int64) (isAllowed bool, userRole database.UserRole, err error)

func (*TestSQLiteDatabase) Login

func (*TestSQLiteDatabase) Login(
	_ context.Context,
	_ string,
	_ int64,
	_ string,
	_ *config.Config,
) (bool, error)

func (*TestSQLiteDatabase) MovieExistsFiles

func (*TestSQLiteDatabase) MovieExistsFiles(_ context.Context, _ []string) (bool, error)

func (*TestSQLiteDatabase) MovieExistsId

func (*TestSQLiteDatabase) MovieExistsId(_ context.Context, _ uint) (bool, error)

func (*TestSQLiteDatabase) MovieExistsUploadedFile

func (*TestSQLiteDatabase) MovieExistsUploadedFile(_ context.Context, _ string) (bool, error)

func (*TestSQLiteDatabase) RemoveFilesByMovieID

func (*TestSQLiteDatabase) RemoveFilesByMovieID(_ context.Context, _ uint) error

func (*TestSQLiteDatabase) RemoveMovie

func (*TestSQLiteDatabase) RemoveMovie(_ context.Context, _ uint) error

Add other required methods...

func (*TestSQLiteDatabase) RemoveTempFilesByMovieID

func (*TestSQLiteDatabase) RemoveTempFilesByMovieID(_ context.Context, _ uint) error

func (*TestSQLiteDatabase) SetLoaded

func (*TestSQLiteDatabase) SetLoaded(_ context.Context, _ uint) error

func (*TestSQLiteDatabase) SetQBittorrentHash added in v1.6.0

func (*TestSQLiteDatabase) SetQBittorrentHash(_ context.Context, _ uint, _ string) error

func (*TestSQLiteDatabase) SetTvCompatibility added in v1.4.0

func (*TestSQLiteDatabase) SetTvCompatibility(_ context.Context, _ uint, _ string) error

func (*TestSQLiteDatabase) UpdateConversionPercentage added in v1.4.0

func (*TestSQLiteDatabase) UpdateConversionPercentage(_ context.Context, _ uint, _ int) error

func (*TestSQLiteDatabase) UpdateConversionStatus added in v1.4.0

func (*TestSQLiteDatabase) UpdateConversionStatus(_ context.Context, _ uint, _ string) error

func (*TestSQLiteDatabase) UpdateDownloadedPercentage

func (*TestSQLiteDatabase) UpdateDownloadedPercentage(_ context.Context, _ uint, _ int) error

func (*TestSQLiteDatabase) UpdateEpisodesProgress added in v1.4.0

func (*TestSQLiteDatabase) UpdateEpisodesProgress(_ context.Context, _ uint, _ int) error

func (*TestSQLiteDatabase) UpdateMovieName added in v1.5.5

func (t *TestSQLiteDatabase) UpdateMovieName(ctx context.Context, movieID uint, name string) error

Jump to

Keyboard shortcuts

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