eventstest

package
v0.115.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package eventstest provides test helpers for asserting on the events a Recorder posts to its notification webhook.

Sink is an in-process HTTP server that captures the eventv1.Event payloads a Recorder posts to its webhook address. It is the notification endpoint side of the recorder: while the Kubernetes Event sink can be inspected via the apiserver, the webhook payload can only be observed by receiving the HTTP POST.

It is intended for use both by the events module's tests and by controllers that embed the Recorder and want to assert on the events they emit. Point a Recorder at Sink.URL(), emit events, then inspect Events or EventsFor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sink

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

Sink is an in-process HTTP server that captures the eventv1.Event payloads a Recorder posts to its webhook address.

Sink is safe for concurrent use.

func NewSink

func NewSink(t testing.TB) *Sink

NewSink starts a Sink and registers its shutdown with t.Cleanup. The caller does not need to call Close explicitly.

func (*Sink) Close

func (s *Sink) Close()

Close shuts down the underlying HTTP server. NewSink already registers this via t.Cleanup; call it directly only when finer control is needed.

func (*Sink) Events

func (s *Sink) Events() []eventv1.Event

Events returns a snapshot copy of the events received so far, in arrival order.

func (*Sink) EventsFor

func (s *Sink) EventsFor(kind, namespace, name string) []eventv1.Event

EventsFor returns a snapshot copy of the received events whose InvolvedObject matches the given kind, namespace and name, in arrival order.

func (*Sink) Reset

func (s *Sink) Reset()

Reset discards all captured events.

func (*Sink) SetStatusCode

func (s *Sink) SetStatusCode(code int)

SetStatusCode sets the HTTP status code the sink returns for every request. It can be called mid-test to change the response. A zero value keeps the default 200.

func (*Sink) URL

func (s *Sink) URL() string

URL returns the address to pass as the Recorder webhook.

Jump to

Keyboard shortcuts

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