fixture

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fixture serves saved tgju.org pages to the test suites.

The pages are real markup, trimmed to a handful of rows per table so the repository stays small, with the giant tooltip attributes stripped. Keeping one copy behind an embed means the parser tests, the client tests and the server tests all agree on what tgju looks like, and that refreshing the fixtures is a single step.

It is an internal package, so importing testing here costs no user of the library anything.

Index

Constants

This section is empty.

Variables

View Source
var Paths = map[string]string{
	"/currency":   "testdata/currency.html",
	"/gold-chart": "testdata/gold.html",
	"/coin":       "testdata/coin.html",
}

Paths maps the tgju.org path of each supported board onto its fixture.

Functions

func Page

func Page(tb testing.TB, path string) []byte

Page returns the saved page for a tgju.org path such as "/currency".

func Server

func Server(tb testing.TB) *httptest.Server

Server starts an HTTP server that answers the tgju.org board paths with the saved pages and everything else with 404. It is shut down when the test ends.

client := tgju.New(tgju.WithBaseURL(fixture.Server(t).URL))

func ServerFunc

func ServerFunc(tb testing.TB, hook func(http.ResponseWriter, *http.Request) bool) *httptest.Server

ServerFunc is Server with a hook that runs before every response. Use it to count requests, to assert on headers, or to fail a request on purpose:

srv := fixture.ServerFunc(t, func(w http.ResponseWriter, r *http.Request) bool {
    w.WriteHeader(http.StatusTooManyRequests)
    return false // the fixture is not written
})

The hook returns false to take over the response entirely.

Types

This section is empty.

Jump to

Keyboard shortcuts

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