testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil holds shared test helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Golden

func Golden(t *testing.T, name, got string)

Golden compares got with testdata/<name>.golden, or rewrites it with `go test -update`. Review golden diffs in pull requests like code.

Types

type Internet

type Internet struct {
	// contains filtered or unexported fields
}

Internet is a pretend public internet for tests of code behind a netguard.Guard: host names resolve to public addresses, and connections to them land on local test servers. The guard's rules stay untouched, so a test server is never reached through its real loopback address.

func NewInternet

func NewInternet() *Internet

NewInternet returns an empty one.

func (*Internet) Guard

func (n *Internet) Guard(allowPrivate func(context.Context) bool) *netguard.Guard

Guard returns a guard that resolves and connects through this internet. allowPrivate may be nil (private networks refused).

func (*Internet) Host

func (n *Internet) Host(name, addr string) *Internet

Host makes name resolve to a public address served by the listener at addr (an httptest server's Listener.Addr().String()).

func (*Internet) LookupIPAddr

func (n *Internet) LookupIPAddr(_ context.Context, host string) ([]net.IPAddr, error)

LookupIPAddr implements netguard.Resolver.

func (*Internet) PrivateHost

func (n *Internet) PrivateHost(name, ip string) *Internet

PrivateHost makes name resolve to an address of a private network.

Jump to

Keyboard shortcuts

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