Documentation
¶
Overview ¶
Package testgen provides utilities for generating test files (EPUB, CBZ, M4B) with configurable metadata for testing the scan worker.
Index ¶
- func CreateSubDir(t *testing.T, parent, name string) string
- func FFmpegAvailable() bool
- func FileExists(path string) bool
- func GenerateCBZ(t *testing.T, dir, filename string, opts CBZOptions) string
- func GenerateEPUB(t *testing.T, dir, filename string, opts EPUBOptions) string
- func GenerateM4B(t *testing.T, dir, filename string, opts M4BOptions) string
- func GenerateM4BWithEAC3(t *testing.T, dir, filename string, opts M4BEAC3Options) string
- func GenerateM4BWithType18Genre(t *testing.T, dir, filename string, opts M4BType18Options) string
- func GetM4BTags(t *testing.T, path string) map[string]string
- func ReadFile(t *testing.T, path string) []byte
- func SkipIfNoFFmpeg(t *testing.T)
- func StringPtr(s string) *string
- func TempDir(t *testing.T, pattern string) string
- func TempLibraryDir(t *testing.T) string
- func WriteFile(t *testing.T, dir, name string, content []byte) string
- type CBZOptions
- type EPUBOptions
- type M4BChapter
- type M4BEAC3Options
- type M4BOptions
- type M4BType18Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSubDir ¶
CreateSubDir creates a subdirectory within the given parent directory. Returns the full path to the created subdirectory.
func FFmpegAvailable ¶
func FFmpegAvailable() bool
FFmpegAvailable checks if ffmpeg is available on the system.
func FileExists ¶
FileExists checks if a file exists at the given path.
func GenerateCBZ ¶
func GenerateCBZ(t *testing.T, dir, filename string, opts CBZOptions) string
GenerateCBZ creates a valid CBZ file at the specified path with the given options. The generated CBZ contains: - ComicInfo.xml (if HasComicInfo is true) - Page images (001.png, 002.png, etc.)
func GenerateEPUB ¶
func GenerateEPUB(t *testing.T, dir, filename string, opts EPUBOptions) string
GenerateEPUB creates a valid EPUB file at the specified path with the given options. The generated EPUB contains mimetype, container.xml, content.opf with metadata, chapter1.xhtml, and optionally a cover image.
func GenerateM4B ¶
func GenerateM4B(t *testing.T, dir, filename string, opts M4BOptions) string
GenerateM4B creates a valid M4B file at the specified path with the given options. This function requires ffmpeg to be installed. Use SkipIfNoFFmpeg() to skip tests when ffmpeg is not available. The generated M4B contains a short audio track, iTunes-style metadata, and optionally a cover image.
func GenerateM4BWithEAC3 ¶ added in v0.0.8
func GenerateM4BWithEAC3(t *testing.T, dir, filename string, opts M4BEAC3Options) string
GenerateM4BWithEAC3 creates a minimal valid M4B file with EAC3 (Dolby Digital Plus) audio. This is a synthetic file that contains the necessary box structure for codec detection but does not contain playable audio data.
func GenerateM4BWithType18Genre ¶
func GenerateM4BWithType18Genre(t *testing.T, dir, filename string, opts M4BType18Options) string
GenerateM4BWithType18Genre creates an M4B file with a genre atom using data type 18 (the problematic type that dhowden/tag doesn't handle).
Strategy: Generate a valid M4B with ffmpeg, then patch the genre data type to 18. This ensures the overall file structure is valid and recognized by parsers.
func GetM4BTags ¶
GetM4BTags reads the metadata tags from an M4B file using ffprobe. Returns a map of tag names to values. This is useful for verifying that tags were correctly written to files.
func SkipIfNoFFmpeg ¶
SkipIfNoFFmpeg skips the test if ffmpeg is not available.
func TempDir ¶
TempDir creates a temporary directory for testing and registers cleanup. The directory is automatically removed when the test completes.
func TempLibraryDir ¶
TempLibraryDir creates a temporary library directory structure for testing. Returns the library path that should be used when creating a library.
Types ¶
type CBZOptions ¶
type CBZOptions struct {
Title string
Series string
SeriesNumber *float64
Writer string
Penciller string
Inker string
Colorist string
Letterer string
CoverArtist string
Editor string
Translator string
PageCount int // defaults to 3
HasComicInfo bool // whether to include ComicInfo.xml
CoverPageType string // "FrontCover", "InnerCover", or "" (none specified)
CoverPageIndex int // 0-indexed page number for cover (used with CoverPageType)
ImageFormat string // "png" or "jpeg", defaults to "png"
ForceEmptyTitle bool // if true, writes an empty <Title></Title> element (for testing empty title handling)
}
CBZOptions configures the generated CBZ file.
type EPUBOptions ¶
type EPUBOptions struct {
Title string
Authors []string
Series string
SeriesNumber *float64
HasCover bool
CoverMimeType string // "image/jpeg" or "image/png", defaults to "image/png"
}
EPUBOptions configures the generated EPUB file.
type M4BChapter ¶
M4BChapter represents a chapter for test M4B generation.
type M4BEAC3Options ¶ added in v0.0.8
type M4BEAC3Options struct {
Title string
Bitrate uint32 // Average bitrate in bps (default: 640000)
}
M4BEAC3Options configures the synthetic EAC3 M4B file.
type M4BOptions ¶
type M4BOptions struct {
Title string
Artist string // Author
Album string // Series/Grouping (e.g., "Series Name #7")
Composer string // Narrator
Genre string // Genre text
Duration float64 // Duration in seconds
HasCover bool
Copyright string // Copyright notice
Date string // Year/date (e.g., "2024")
AlbumArtist string // Album artist (different from artist)
Comment string // Comment/description
Chapters []M4BChapter
}
M4BOptions configures the generated M4B file.
type M4BType18Options ¶
M4BType18Options configures the synthetic M4B file with data type 18 genre.