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 ¶
- Variables
- func CopyFile(src, dst string) error
- func SamplePDF() string
- func TempDir(prefix string) (string, func())
- func TempFile(prefix, content string) (string, func())
- func TestImage() string
- func TestdataDir() string
- type MockOCRBackend
- type MockPDFOps
- func (m *MockPDFOps) AssertCalled(prefix string) bool
- func (m *MockPDFOps) Compress(input, output, _ string) error
- func (m *MockPDFOps) ExtractText(input, _ string, _ []int) (string, error)
- func (m *MockPDFOps) Merge(_ []string, output, _ string) error
- func (m *MockPDFOps) PageCount(file, _ string) (int, error)
- func (m *MockPDFOps) Reset()
- func (m *MockPDFOps) Split(input, _, _ string) error
Constants ¶
This section is empty.
Variables ¶
var ErrMockCorrupted = errors.New("mock: file corrupted")
ErrMockCorrupted is a mock error for corrupted files.
var ErrMockPasswordRequired = errors.New("mock: password required")
ErrMockPasswordRequired is a mock error for password-protected files.
Functions ¶
func TempDir ¶
TempDir creates a temporary directory for test artifacts. Returns the path and a cleanup function.
func TempFile ¶
TempFile creates a temporary file with the given content. Returns the path and a cleanup function.
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) ProcessImage ¶
ProcessImage mocks OCR processing.
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) Split ¶
func (m *MockPDFOps) Split(input, _, _ string) error
Split mocks pdf.Split.