testutil

package
v0.3.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 14 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 testutil builds a bridge with fake collaborators, for the tests of the packages above it.

Index

Constants

View Source
const GroupKey = `{}:{alertname="ServiceDown",service="hub-example-com"}`

GroupKey is the key of the group New fires; GroupID is its id.

Variables

This section is empty.

Functions

func GroupID

func GroupID() string

GroupID returns the id of the group New fires.

func ProbeBoard

func ProbeBoard(t *testing.T) *probenow.Board

ProbeBoard is a board of requests to probe on demand over two locations, edge-1 (overseas) and edge-2 (mainland), and these target sets:

all-web.yaml       https://hub.example.com/ (service hub-example-com, the alert's; module http_head)
all-tls.yaml       https://hub.example.com/ again, module tls_expiry
all-docs.yaml      https://docs.example.com/ and https://www.example.com/ (service docs)
overseas-api.yaml  https://api.example.com/ (service api): edge-1 alone probes it

Types

type AM

type AM struct {
	Created []map[string]string
	Agents  []map[string]string // agents' silences, which mute nothing
	Expired []string
	// contains filtered or unexported fields
}

AM is a fake silencer, standing in for the router.

func (*AM) CreateAgentSilence

func (a *AM) CreateAgentSilence(_ context.Context, l map[string]string, _, _ time.Time, _, _ string) (string, error)

func (*AM) CreateSilence

func (a *AM) CreateSilence(_ context.Context, l map[string]string, _, _ time.Time, _, _ string) (string, error)

func (*AM) ExpireSilence

func (a *AM) ExpireSilence(_ context.Context, id string) error

func (*AM) Silences

func (a *AM) Silences(context.Context) ([]alertmanager.Silence, error)

type Bot

type Bot struct {
	Texts []string
	// contains filtered or unexported fields
}

Bot is a fake group bot.

func (*Bot) Send

func (b *Bot) Send(_ context.Context, t string) error

type Env

type Env struct {
	Bridge *bridge.Bridge
	Store  *store.Store
	AM     *AM
	Bot    *Bot
	// Location is the configured zone, the one the bridge formats times with; tests that check
	// formatted dates read it rather than the process's own zone (CI runs UTC, the config does not).
	Location *time.Location
}

Env is a bridge on a temporary store, with no Feishu app (alerts go to the fake bot).

func New

func New(t *testing.T) *Env

New creates an Env with one critical alert group firing; its id is GroupID.

func NewWith

func NewWith(t *testing.T, tweak func(*bridge.Deps)) *Env

NewWith is New with a last word on the bridge's dependencies, for tests that add a collaborator.

func WithAgentRun

func WithAgentRun(t *testing.T) *Env

WithAgentRun seeds a pending reference delivery without making a network call.

func (*Env) Token

func (e *Env) Token(t *testing.T, name string, scopes ...string) string

Token creates a token with scopes and returns its secret. A token with people's scopes is given access to all machines that are not critical, as beacon token create -machines all gives it; tests of a narrower access set it themselves.

Jump to

Keyboard shortcuts

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