testing

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testing provides test utilities, mocks, and fixtures for pdf-cli tests.

This package should only be imported in test files (*_test.go).

Index

Constants

This section is empty.

Variables

View Source
var ErrMockCorrupted = errors.New("mock: file corrupted")

ErrMockCorrupted is a mock error for corrupted files.

View Source
var ErrMockPasswordRequired = errors.New("mock: password required")

ErrMockPasswordRequired is a mock error for password-protected files.

Functions

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies a file from src to dst for test isolation.

func SamplePDF

func SamplePDF() string

SamplePDF returns the path to sample.pdf in testdata.

func TempDir

func TempDir(prefix string) (string, func())

TempDir creates a temporary directory for test artifacts. Returns the path and a cleanup function.

func TempFile

func TempFile(prefix, content string) (string, func())

TempFile creates a temporary file with the given content. Returns the path and a cleanup function.

func TestImage

func TestImage() string

TestImage returns the path to test_image.png in testdata.

func TestdataDir

func TestdataDir() string

TestdataDir returns the path to the testdata directory. It handles being called from any package by finding the project root.

Types

type MockOCRBackend

type MockOCRBackend struct {
	// NameResult is returned by Name
	NameResult string
	// AvailableResult is returned by Available
	AvailableResult bool
	// ProcessImageResult is returned by ProcessImage
	ProcessImageResult string
	// ProcessImageError is returned by ProcessImage if set
	ProcessImageError error
	// Calls tracks which methods were called
	Calls []string
}

MockOCRBackend provides a mock OCR backend for testing.

func NewMockOCRBackend

func NewMockOCRBackend() *MockOCRBackend

NewMockOCRBackend creates a MockOCRBackend with sensible defaults.

func (*MockOCRBackend) Available

func (m *MockOCRBackend) Available() bool

Available returns whether the backend is available.

func (*MockOCRBackend) Close

func (m *MockOCRBackend) Close() error

Close mocks backend cleanup.

func (*MockOCRBackend) Name

func (m *MockOCRBackend) Name() string

Name returns the backend name.

func (*MockOCRBackend) ProcessImage

func (m *MockOCRBackend) ProcessImage(_ context.Context, imagePath, _ string) (string, error)

ProcessImage mocks OCR processing.

func (*MockOCRBackend) Reset

func (m *MockOCRBackend) Reset()

Reset clears the call history.

type MockPDFOps

type MockPDFOps struct {
	// PageCountResult is returned by PageCount
	PageCountResult int
	// PageCountError is returned by PageCount if set
	PageCountError error
	// CompressError is returned by Compress if set
	CompressError error
	// MergeError is returned by Merge if set
	MergeError error
	// SplitError is returned by Split if set
	SplitError error
	// ExtractTextResult is returned by ExtractText
	ExtractTextResult string
	// ExtractTextError is returned by ExtractText if set
	ExtractTextError error
	// Calls tracks which methods were called
	Calls []string
}

MockPDFOps provides mock PDF operations for testing commands without requiring actual PDF files.

func NewMockPDFOps

func NewMockPDFOps() *MockPDFOps

NewMockPDFOps creates a MockPDFOps with sensible defaults.

func (*MockPDFOps) AssertCalled

func (m *MockPDFOps) AssertCalled(prefix string) bool

AssertCalled checks if a method was called with the given prefix.

func (*MockPDFOps) Compress

func (m *MockPDFOps) Compress(input, output, _ string) error

Compress mocks pdf.Compress.

func (*MockPDFOps) ExtractText

func (m *MockPDFOps) ExtractText(input, _ string, _ []int) (string, error)

ExtractText mocks pdf.ExtractText.

func (*MockPDFOps) Merge

func (m *MockPDFOps) Merge(_ []string, output, _ string) error

Merge mocks pdf.Merge.

func (*MockPDFOps) PageCount

func (m *MockPDFOps) PageCount(file, _ string) (int, error)

PageCount mocks pdf.PageCount.

func (*MockPDFOps) Reset

func (m *MockPDFOps) Reset()

Reset clears the call history.

func (*MockPDFOps) Split

func (m *MockPDFOps) Split(input, _, _ string) error

Split mocks pdf.Split.

Jump to

Keyboard shortcuts

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