fake

package
v0.0.2 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fake provides in-process stand-ins for external services that the acceptance and chaos drivers need: an ntfy server that records messages and an HTTP monitor target that can be switched between healthy and failing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	At       time.Time
	Path     string
	Title    string
	Priority string
	Tags     string
	Body     string
}

Message is one notification that Shoutrrr's ntfy service posted.

type Recorder

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

Recorder is an in-process stand-in for an ntfy server. It accepts POST /<topic> as Shoutrrr's ntfy service sends it (plain-text body, Title, Priority and Tags headers) and records every message with its arrival time.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns an empty recorder that stamps messages with time.Now.

func (*Recorder) Messages

func (r *Recorder) Messages() []Message

Messages returns a snapshot of all recorded messages.

func (*Recorder) ServeHTTP

func (r *Recorder) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

func (*Recorder) WaitFor

func (r *Recorder) WaitFor(ctx context.Context, since time.Time, match func(Message) bool) (Message, bool)

WaitFor returns the first recorded message that arrived at or after since and satisfies match. It polls until ctx ends.

type Server

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

Server is an HTTP server on a host port, started in the background.

func Listen

func Listen(addr string, h http.Handler) (*Server, error)

Listen binds addr (for example ":18950") and serves h in the background.

func (*Server) Close

func (s *Server) Close() error

Close stops the server and waits up to five seconds for open requests.

func (*Server) Port

func (s *Server) Port() int

Port returns the bound TCP port.

type Target

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

Target is the HTTP monitor target. It answers 200 OK while healthy and 503 Service Unavailable while failing. A 503 is deterministic and keeps the listener open, so the node sees a clean HTTP error instead of a connection error. Every request is counted per path.

func NewTarget

func NewTarget() *Target

NewTarget returns a healthy target without recorded hits.

func (*Target) Failing

func (t *Target) Failing() bool

Failing reports whether the target currently answers 503.

func (*Target) Hits

func (t *Target) Hits(path string) int

Hits returns how many requests arrived for the given URL path.

func (*Target) ServeHTTP

func (t *Target) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Target) SetFailing

func (t *Target) SetFailing(failing bool)

SetFailing switches between 503 (true) and 200 (false).

func (*Target) TotalHits

func (t *Target) TotalHits() int

TotalHits returns the number of requests for all paths.

Jump to

Keyboard shortcuts

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