package testhelper
import "golang.org/x/pkgsite/internal/testing/testhelper"
Package testhelper provides shared functionality and constants to be used in Discovery tests. It should only be imported by test files.
Index ¶
- Constants
- func CompareWithGolden(t *testing.T, got, filename string, update bool)
- func CreateTestDirectory(files map[string]string) (_ string, err error)
- func SetupTestClientAndServer(handler http.Handler) (*http.Client, *httptest.Server, func())
- func TestDataPath(rel string) string
- func WriteTxtarToTempDir(t *testing.T, data string) (string, map[string]string)
- func ZipContents(contents map[string]string) ([]byte, error)
Constants ¶
const ( MITLicense = "" /* 1051 byte string literal not displayed */ BSD0License = "" /* 635 byte string literal not displayed */ UnknownLicense = `THIS IS A LICENSE THAT I JUST MADE UP. YOU CAN DO WHATEVER YOU WANT WITH THIS CODE, TRUST ME.` )
Functions ¶
func CompareWithGolden ¶
func CreateTestDirectory ¶
CreateTestDirectory creates a directory to hold a module when testing local fetching, and returns the directory.
func SetupTestClientAndServer ¶
SetupTestClientAndServer returns a *httpClient that can be used to stub requests to remote hosts by redirecting all requests that the client makes to a httptest.Server. with the given handler. It also disables TLS verification.
func TestDataPath ¶
TestDataPath returns a path corresponding to a path relative to the calling test file. For convenience, rel is assumed to be "/"-delimited.
It panics on failure.
func WriteTxtarToTempDir ¶
WriteTxtarToTempDir parses data as a txtar archive, and writes the resulting files to a new tempdir created with t.TempDir(). It returns the temp directory and files that were unpacked.
func ZipContents ¶
ZipContents creates an in-memory zip of the given contents.
Source Files ¶
testhelper.go
- Version
- v0.0.0-20250218150137-224a1368cf02 (latest)
- Published
- Feb 18, 2025
- Platform
- linux/amd64
- Imports
- 16 packages
- Last checked
- 2 months ago –
Tools for package owners.