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 ¶
- func CaptureGalleryResponse(t *testing.T, galleryID string, encoding string) []byte
- func FindAllElements(n *html.Node, match func(*html.Node) bool) []*html.Node
- func FindElement(n *html.Node, match func(*html.Node) bool) *html.Node
- func FindElementByClass(n *html.Node, class string) *html.Node
- func FindElementByID(n *html.Node, id string) *html.Node
- func FindElementByTag(n *html.Node, tag string) *html.Node
- func GenerateGalleryHTML(sizeBytes int) string
- func GenerateRandomBytes(sizeBytes int) []byte
- func GetAttr(n *html.Node, key string) string
- func GetTextContent(n *html.Node) string
- func LoadTestDatabase(t *testing.T) *dbconnpool.DbSQLConnPool
- func MakeHTTPCacheEntry(path string, payload []byte, encoding string) *cachelite.HTTPCacheEntry
- func ParseHTML(r io.Reader) (*html.Node, error)
- type FakeImporter
- type FakeQueries
- func (f *FakeQueries) GetFileByPath(ctx context.Context, path string) (gallerydb.File, error)
- func (f *FakeQueries) GetFolderTileExistsViewByPath(ctx context.Context, path string) (bool, error)
- func (f *FakeQueries) GetThumbnailExistsViewByID(ctx context.Context, id int64) (bool, error)
- func (f *FakeQueries) UpsertExif(ctx context.Context, p gallerydb.UpsertExifParams) error
- func (f *FakeQueries) WithTx(tx *sql.Tx) ThumbnailTx
- type FakeQueriesForCheck
- func (f *FakeQueriesForCheck) GetFileByPath(ctx context.Context, path string) (gallerydb.File, error)
- func (f *FakeQueriesForCheck) GetFolderTileExistsViewByPath(ctx context.Context, path string) (bool, error)
- func (f *FakeQueriesForCheck) GetThumbnailExistsViewByID(ctx context.Context, id int64) (bool, error)
- func (f *FakeQueriesForCheck) UpsertExif(ctx context.Context, p gallerydb.UpsertExifParams) error
- func (f *FakeQueriesForCheck) WithTx(tx *sql.Tx) ThumbnailTx
- type FakeThumbnailTxFailBlob
- type FakeThumbnailTxSuccess
- type ThumbnailTx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureGalleryResponse ¶
CaptureGalleryResponse gets real HTTP response from handler (Approach #1) Note: Implementation requires actual app instance and test setup
func FindAllElements ¶
FindAllElements returns all nodes matching the predicate.
func FindElement ¶
FindElement traverses the tree and returns the first node matching the predicate.
func FindElementByClass ¶
FindElementByClass finds the first element containing the given class.
func FindElementByID ¶
FindElementByID finds an element by its id attribute.
func FindElementByTag ¶
FindElementByTag finds the first element with the given tag name.
func GenerateGalleryHTML ¶
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 ¶
GenerateRandomBytes generates random data of exact size
func GetTextContent ¶
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
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
type FakeQueries ¶
type FakeQueries struct{}
FakeQueries is a minimal fake implementing the QueriesForFiles contract for tests.
func (*FakeQueries) GetFileByPath ¶
func (*FakeQueries) GetFolderTileExistsViewByPath ¶
func (*FakeQueries) GetThumbnailExistsViewByID ¶
func (*FakeQueries) UpsertExif ¶
func (f *FakeQueries) UpsertExif(ctx context.Context, p gallerydb.UpsertExifParams) error
func (*FakeQueries) WithTx ¶
func (f *FakeQueries) WithTx(tx *sql.Tx) ThumbnailTx
type FakeQueriesForCheck ¶
FakeQueriesForCheck is a fake implementation of the QueriesForFiles interface specifically designed to allow controlled returns for the GetFileByPath method.
func (*FakeQueriesForCheck) GetFileByPath ¶
func (*FakeQueriesForCheck) GetFolderTileExistsViewByPath ¶
func (*FakeQueriesForCheck) GetThumbnailExistsViewByID ¶
func (*FakeQueriesForCheck) UpsertExif ¶
func (f *FakeQueriesForCheck) UpsertExif(ctx context.Context, p gallerydb.UpsertExifParams) error
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 (f *FakeThumbnailTxFailBlob) UpsertThumbnailBlob(ctx context.Context, p gallerydb.UpsertThumbnailBlobParams) error
func (*FakeThumbnailTxFailBlob) UpsertThumbnailReturningID ¶
func (f *FakeThumbnailTxFailBlob) UpsertThumbnailReturningID(ctx context.Context, p gallerydb.UpsertThumbnailReturningIDParams) (int64, error)
type FakeThumbnailTxSuccess ¶
FakeThumbnailTxSuccess is a fake implementation of ThumbnailTx that simulates a successful transaction, recording whether its methods were called.
func (*FakeThumbnailTxSuccess) UpsertThumbnailBlob ¶
func (f *FakeThumbnailTxSuccess) UpsertThumbnailBlob(ctx context.Context, p gallerydb.UpsertThumbnailBlobParams) error
func (*FakeThumbnailTxSuccess) UpsertThumbnailReturningID ¶
func (f *FakeThumbnailTxSuccess) UpsertThumbnailReturningID(ctx context.Context, p gallerydb.UpsertThumbnailReturningIDParams) (int64, error)
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.