testgen

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package testgen provides utilities for generating test files (EPUB, CBZ, M4B) with configurable metadata for testing the scan worker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSubDir

func CreateSubDir(t *testing.T, parent, name string) string

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

func FileExists(path string) bool

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

func GetM4BTags(t *testing.T, path string) map[string]string

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 ReadFile

func ReadFile(t *testing.T, path string) []byte

ReadFile reads and returns the contents of a file.

func SkipIfNoFFmpeg

func SkipIfNoFFmpeg(t *testing.T)

SkipIfNoFFmpeg skips the test if ffmpeg is not available.

func StringPtr

func StringPtr(s string) *string

StringPtr is a helper to create a pointer to a string.

func TempDir

func TempDir(t *testing.T, pattern string) string

TempDir creates a temporary directory for testing and registers cleanup. The directory is automatically removed when the test completes.

func TempLibraryDir

func TempLibraryDir(t *testing.T) string

TempLibraryDir creates a temporary library directory structure for testing. Returns the library path that should be used when creating a library.

func WriteFile

func WriteFile(t *testing.T, dir, name string, content []byte) string

WriteFile creates a file with the given content in the specified directory. Returns the full path to the created file.

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

type M4BChapter struct {
	Title string
	Start float64 // Start time in seconds
}

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

type M4BType18Options struct {
	Title string
	Genre string // Will be written with data type 18
}

M4BType18Options configures the synthetic M4B file with data type 18 genre.

Jump to

Keyboard shortcuts

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