engtest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package engtest includes a number of helpers for testing search engines.

engtest aids in testing engines and comparing any number of inputs with their expected outputs. It does this by mocking the HTTP client and then attempting to search as normal.

Considerations for queries

Some search engines don't have stable output and as a result your engine might need to work with several different types of responses; Google is such an engine where sometimes a result is slightly different from the rest and a complete extraction of all data for a result might not happen. While the Google engine is usually capable of finding the title and link, it can have trouble with the description.

As such, try to construct enough test cases to maximize your coverage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.2.1

type Config struct {
	// When set, engtest will ignore empty descriptions in search results.
	IgnoreEmptyDescription bool
}

Special configuration options for engtest.

type TestData

type TestData struct {
	Req request
	Res response
}

Request/response pair for testdata.

type Tester

type Tester struct {
	Config
	// contains filtered or unexported fields
}

Tester is the contextual struct for testing engines.

func New

func New(driver string, cfg search.Config, ecfg ...Config) *Tester

New creates a new Tester from an engine name and a base config.

The contents of the configuration struct is not important, however engtest will always set a name based on the test case that is being run and will flip Debug to true.

If a driver is not supported, New panics.

func (*Tester) RunTest

func (tt *Tester) RunTest(t *testing.T, query string)

RunTest runs a test for an engine on a specific query.

engtest will initialize the engine, load the test file, and then will perform a query while mocking the other end of the connection.

If -update was passed to go test, then the search queries will actually be performed and their results will be saved to disk.

func (*Tester) RunTests

func (tt *Tester) RunTests(t *testing.T, queries ...string)

RunTests is a wrapper function around [RunTest] to run several tests at once.

If -update is passed to go test, RunTests will introduce a 3 second delay between test runs to prevent your IP address from being blocked from accessing the search engine.

Directories

Path Synopsis
git.sr.ht/~cmcevoy/srchd/internal/engtest/tool is a very rudimentary tool to extract requests and responses to search engines from their test files.
git.sr.ht/~cmcevoy/srchd/internal/engtest/tool is a very rudimentary tool to extract requests and responses to search engines from their test files.

Jump to

Keyboard shortcuts

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