Documentation
¶
Overview ¶
Package testenv runs command tests against a real API server: one envtest (kube-apiserver and etcd) per test package with the Gateway API and kgateway CRDs, behind fault-injecting proxies (design §10).
A package using it calls Run from TestMain and New from each test. Tests using it never call t.Parallel.
Index ¶
Constants ¶
const ( // KindAcquire is a classic LIST, or a WATCH with sendInitialEvents=true. KindAcquire = "acquire" // KindWatch is a WATCH without sendInitialEvents=true. KindWatch = "watch" // KindDiscovery is a GET under /api, /apis or /version that names no resource. KindDiscovery = "discovery" )
Request kinds a Match selects.
Variables ¶
This section is empty.
Functions ¶
func ClassicWatch ¶
ClassicWatch turns the WatchListClient feature gate off, so informers use a classic LIST then WATCH, and restores the previous gates at cleanup. Call it before starting any informer.
func ContextName ¶
ContextName returns the kubeconfig context name of Env.Proxies[i].
func ProxyPodSelector ¶
ProxyPodSelector returns the label selector the cache sends on its proxy Pod requests: that of the first registered detector that selects proxy Pods, or "" when none does. Use it as Match.LabelSelector.
Types ¶
type Action ¶
type Action struct {
Delay time.Duration
// Until, if set, holds the request until the channel is closed.
Until <-chan struct{}
Status int
RetryAfter int // seconds, sent with Status
// HoldWatchThenStatus keeps a plain watch open until the matching LIST has
// completed plus 200ms, then answers with this status.
HoldWatchThenStatus int
}
Action is the fault applied to a matching request. Delay runs first, then Until; then Status, if set, answers instead of envtest.
type Env ¶
type Env struct {
// Kubeconfig is the path of a kubeconfig with one context per proxy:
// ContextName(i) points at Proxies[i], and ContextName(0) is current.
Kubeconfig string
Proxies []*Proxy
// Admin talks to envtest directly, bypassing the proxies.
Admin *rest.Config
}
Env is one test's view of the package's envtest.
func New ¶
New returns an Env with opts.Contexts proxies in front of the package's envtest and opts.Fixtures applied. At cleanup it fails the test for every rule that never matched, closes the proxies, and deletes every object it created, waiting until each is gone. Namespaces are created if absent and never deleted: envtest has no namespace controller to finish a deletion.
type Match ¶
type Match struct {
// Kind is KindAcquire, KindWatch or KindDiscovery; it is ignored when Subresource is set.
Kind string
// Resource is "pods" for the core group and "<resource>.<group>" otherwise.
// For discovery it is "*" for every request, or the group version ("v1",
// "gateway.networking.k8s.io/v1").
Resource string
// LabelSelector is compared as a parsed selector; "" matches any.
LabelSelector string
// Subresource, if set, selects requests of any verb to an object's
// subresource, such as "proxy" for pods/<name>/proxy/... or a POST to
// "portforward"; Kind and LabelSelector are then ignored.
Subresource string
}
Match selects requests by kind, resource and label selector, or a named object's subresource.
type Options ¶
type Options struct {
// Fixtures are YAML files applied as admin, relative to the test's working
// directory. A status in a fixture is written through the status subresource.
Fixtures []string
// Contexts is the number of proxies, one kubeconfig context each; 0 means 1.
Contexts int
// CRDDirs are CRD files or directories installed in addition to the
// Gateway API and kgateway CRDs.
CRDDirs []string
}
Options configures one test's Env.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is an httptest reverse proxy in front of envtest that injects faults. Requests reach envtest as the admin user.
func (*Proxy) OpenConns ¶
OpenConns returns the number of client connections not yet closed or hijacked.
func (*Proxy) OpenWatches ¶
OpenWatches returns the number of watch requests currently open.
func (*Proxy) WatchesSeen ¶
WatchesSeen returns the number of watch requests received so far.
type RuleHits ¶
type RuleHits struct {
// contains filtered or unexported fields
}
RuleHits counts the requests a rule applied to.
func (*RuleHits) ClientGone ¶
func (h *RuleHits) ClientGone() <-chan struct{}
ClientGone is closed once a client went away while the rule held its request.