testutil

package
v0.1.149 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package testutil provides helper functions for benchmarking the HTTP cache

Package testutil provides helper functions and fake implementations of interfaces used throughout the application, primarily for facilitating isolated unit testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureGalleryResponse

func CaptureGalleryResponse(t *testing.T, galleryID string, encoding string) []byte

CaptureGalleryResponse gets real HTTP response from handler (Approach #1) Note: Implementation requires actual app instance and test setup

func FindAllElements

func FindAllElements(n *html.Node, match func(*html.Node) bool) []*html.Node

FindAllElements returns all nodes matching the predicate.

func FindElement

func FindElement(n *html.Node, match func(*html.Node) bool) *html.Node

FindElement traverses the tree and returns the first node matching the predicate.

func FindElementByClass

func FindElementByClass(n *html.Node, class string) *html.Node

FindElementByClass finds the first element containing the given class.

func FindElementByID

func FindElementByID(n *html.Node, id string) *html.Node

FindElementByID finds an element by its id attribute.

func FindElementByTag

func FindElementByTag(n *html.Node, tag string) *html.Node

FindElementByTag finds the first element with the given tag name.

func GenerateGalleryHTML

func GenerateGalleryHTML(sizeBytes int) string

GenerateGalleryHTML creates synthetic HTML response with controlled size (Approach #2). HTML content uses string concatenation with loops (rather than templates) because: - This is a benchmark utility for generating variable-size payloads - Dynamic size generation using loops cannot be expressed naturally in templates - Performance-critical path: string building must be as fast as possible - No conditional rendering or complex template logic needed - Test-only utility that generates realistic HTML for HTTP cache benchmarking

func GenerateRandomBytes

func GenerateRandomBytes(sizeBytes int) []byte

GenerateRandomBytes generates random data of exact size

func GetAttr

func GetAttr(n *html.Node, key string) string

GetAttr returns the value of an attribute, or empty string if not found.

func GetTextContent

func GetTextContent(n *html.Node) string

GetTextContent returns all text content within a node.

func LoadTestDatabase

func LoadTestDatabase(t *testing.T) *dbconnpool.DbSQLConnPool

LoadTestDatabase decompresses testdata/sfpg.db.gz and returns initialized *dbconnpool.DbSQLConnPool This helper loads the real test dataset for benchmark use (Approach #1: Real Data)

func MakeHTTPCacheEntry

func MakeHTTPCacheEntry(path string, payload []byte, encoding string) *cachelite.HTTPCacheEntry

MakeHTTPCacheEntry builds a cache entry for benchmark seeding

func ParseHTML

func ParseHTML(r io.Reader) (*html.Node, error)

ParseHTML parses an io.Reader into an html.Node.

Types

type FakeImporter

type FakeImporter struct {
	UpsertPathChainFunc       func(ctx context.Context, path string, mtime, size int64, md5 string, phash, width, height int64, mimeType string) (gallerydb.File, error)
	UpdateFolderTileChainFunc func(ctx context.Context, folderID, tileFileID int64) error
}

FakeImporter is a fake implementation of the Importer interface.

func (*FakeImporter) UpdateFolderTileChain

func (f *FakeImporter) UpdateFolderTileChain(ctx context.Context, folderID, tileFileID int64) error

func (*FakeImporter) UpsertPathChain

func (f *FakeImporter) UpsertPathChain(ctx context.Context, path string, mtime, size int64, md5 string, phash, width, height int64, mimeType string) (gallerydb.File, error)

type FakeQueries

type FakeQueries struct{}

FakeQueries is a minimal fake implementing the QueriesForFiles contract for tests.

func (*FakeQueries) GetFileByPath

func (f *FakeQueries) GetFileByPath(ctx context.Context, path string) (gallerydb.File, error)

func (*FakeQueries) GetFolderTileExistsViewByPath

func (f *FakeQueries) GetFolderTileExistsViewByPath(ctx context.Context, path string) (bool, error)

func (*FakeQueries) GetThumbnailExistsViewByID

func (f *FakeQueries) GetThumbnailExistsViewByID(ctx context.Context, id int64) (bool, error)

func (*FakeQueries) UpsertExif

func (*FakeQueries) WithTx

func (f *FakeQueries) WithTx(tx *sql.Tx) ThumbnailTx

type FakeQueriesForCheck

type FakeQueriesForCheck struct {
	Ret gallerydb.File
	Err error
}

FakeQueriesForCheck is a fake implementation of the QueriesForFiles interface specifically designed to allow controlled returns for the GetFileByPath method.

func (*FakeQueriesForCheck) GetFileByPath

func (f *FakeQueriesForCheck) GetFileByPath(ctx context.Context, path string) (gallerydb.File, error)

func (*FakeQueriesForCheck) GetFolderTileExistsViewByPath

func (f *FakeQueriesForCheck) GetFolderTileExistsViewByPath(ctx context.Context, path string) (bool, error)

func (*FakeQueriesForCheck) GetThumbnailExistsViewByID

func (f *FakeQueriesForCheck) GetThumbnailExistsViewByID(ctx context.Context, id int64) (bool, error)

func (*FakeQueriesForCheck) UpsertExif

func (*FakeQueriesForCheck) WithTx

func (f *FakeQueriesForCheck) WithTx(tx *sql.Tx) ThumbnailTx

type FakeThumbnailTxFailBlob

type FakeThumbnailTxFailBlob struct{}

FakeThumbnailTxFailBlob is a fake implementation of ThumbnailTx that simulates a transaction where the UpsertThumbnailBlob operation fails.

func (*FakeThumbnailTxFailBlob) UpsertThumbnailBlob

func (*FakeThumbnailTxFailBlob) UpsertThumbnailReturningID

type FakeThumbnailTxSuccess

type FakeThumbnailTxSuccess struct {
	CalledReturnID bool
	CalledBlob     bool
	ReturnID       int64
}

FakeThumbnailTxSuccess is a fake implementation of ThumbnailTx that simulates a successful transaction, recording whether its methods were called.

func (*FakeThumbnailTxSuccess) UpsertThumbnailBlob

func (*FakeThumbnailTxSuccess) UpsertThumbnailReturningID

type ThumbnailTx

type ThumbnailTx interface {
	UpsertThumbnailReturningID(ctx context.Context, p gallerydb.UpsertThumbnailReturningIDParams) (int64, error)
	UpsertThumbnailBlob(ctx context.Context, p gallerydb.UpsertThumbnailBlobParams) error
}

ThumbnailTx is a local, narrow interface defining the transaction-scoped methods required for thumbnail operations. It is redefined here to avoid a direct dependency on internal interfaces from other packages in test fakes.

Jump to

Keyboard shortcuts

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