testutil

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package testutil starts the throwaway Redis the nova-sprint controls share. One helper, so a missing redis-server has one answer: skip on a laptop, fail when NOVA_CI=1. The process is private. It is not the fleet store, and this file names no bench address.

Index

Constants

View Source
const CIEnv = "NOVA_CI"

CIEnv is set to "1" by the CI workflows. A missing redis-server fails the test in that environment. Anywhere else it skips, so a laptop without the binary can still run the rest of the suite.

Variables

This section is empty.

Functions

func Absent

func Absent(t *testing.T, cause error)

Absent is Start's answer when redis-server is not on PATH. CI fails closed. A skip here would let a green run be a run that never executed the store.

func CommandCounter

func CommandCounter(t *testing.T) (addr string, count func() int64)

CommandCounter listens on 127.0.0.1 and counts every command a Redis client sends it, handshake included. It answers just enough RESP2 for a go-redis client to finish a command: HELLO is refused so the client falls back to RESP2, PING is PONG and anything else is OK. A test calls a package's Open or Dial against the address and asserts the count is still zero: the caller's first batch, not the open, is the first command.

func FreePort

func FreePort(t *testing.T) string

FreePort takes a free loopback port and returns it as text. Redis treats --port 0 as "do not listen", so the port is taken here and handed over.

func Program

func Program(t *testing.T) string

Program is the redis-server on PATH, or Absent's answer when there is none. A test that launches the server through its own production path (nova-redis serve) takes the program from here, so the missing-binary rule stays one.

func Start

func Start(t *testing.T, extra ...string) string

Start runs a throwaway redis-server on 127.0.0.1 and returns host:port. The server uses --save "" and no append-only file, in the test's temporary directory, and the cleanup kills it. Extra arguments follow the fixed ones (for example --user lines that turn the default user off, the fleet shape); a NOAUTH answer to the readiness PING is a live server.

Redis treats --port 0 as "do not listen" (it logs "Configured to not listen anywhere" and exits). The ephemeral port is taken here and handed to redis-server as --port. That is a free loopback port, not a dial to a bench.

Types

type GitHubStub

type GitHubStub struct {
	Server *httptest.Server
	URL    string
	// Env carries GITHUB_API_URL and GH_HOST for a caller to append to a
	// child's cmd.Env, so a child honoring the standard GitHub variables
	// targets the stub without this process changing its own environment.
	Env []string
	// contains filtered or unexported fields
}

GitHubStub is an HTTP server standing in for GitHub in tests. The lander path (eval, serve, worker) reads only git remotes and Redis records; any HTTP call to GitHub on that path is forbidden (O6, L18). When contacted, the stub records the call and fails the test.

func StartGitHubStub

func StartGitHubStub(t *testing.T) *GitHubStub

StartGitHubStub starts an httptest.Server that fails t on any HTTP request. It returns the environment a child needs to target the stub (GITHUB_API_URL and GH_HOST) in GitHubStub.Env, a per-test seam in place of t.Setenv, so the test can run in parallel.

func (*GitHubStub) Calls

func (g *GitHubStub) Calls() int64

Calls returns the count of HTTP requests received by the stub.

type LocalRemote

type LocalRemote struct {
	Dir string // Absolute filesystem path to the bare repo
	URL string // file:// transport URL
}

LocalRemote is a local bare git repository configured to enforce dev-integrity. Its hooks refuse non-fast-forward pushes and ref deletions.

func NewLocalRemote

func NewLocalRemote(t *testing.T, defaultBranch string) *LocalRemote

NewLocalRemote creates a local bare git repository initialized with defaultBranch. It installs update and pre-receive hooks that enforce fast-forward only updates.

Directories

Path Synopsis
Package pg starts the throwaway Postgres the nova-config functional tests share, the way pkg/nsprint/testutil starts a throwaway Redis: initdb and pg_ctl from the binaries on PATH (or the well-known install directories, or NOVA_PG_BIN), a free loopback port, everything under the test's temporary directory, trust authentication, and the cleanup stops it.
Package pg starts the throwaway Postgres the nova-config functional tests share, the way pkg/nsprint/testutil starts a throwaway Redis: initdb and pg_ctl from the binaries on PATH (or the well-known install directories, or NOVA_PG_BIN), a free loopback port, everything under the test's temporary directory, trust authentication, and the cleanup stops it.

Jump to

Keyboard shortcuts

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