testenv

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package testenv holds the live-Docker test helpers shared by both test/e2e (tests that exercise a real api.Router over HTTP) and test/e2e/reconcile (tests that drive the reconciler/Docker runtime directly, with no internal/api dependency). Splitting these out keeps internal/api out of test/e2e/reconcile's import graph, so a PR that only touches internal/api no longer selects that package too.

Index

Constants

View Source
const LiveSuiteEnv = "LEVELRAIL_LIVE_SUITE"

LiveSuiteEnv selects the live suite size: "smoke" runs the PR subset, anything else (unset locally and in nightly) runs everything.

Variables

This section is empty.

Functions

func AssertContainerAbsent

func AssertContainerAbsent(ctx context.Context, t *testing.T, runtime docker.Runtime, containerName, label string)

AssertContainerAbsent fails t unless containerName no longer exists.

func CleanupContainers

func CleanupContainers(ctx context.Context, t *testing.T, rt docker.Runtime, serviceName string)

CleanupContainers stops and removes every container whose name has serviceName as a prefix, ignoring errors so it is safe to call before a run and again from t.Cleanup.

func DoGet

func DoGet(client *http.Client, url string) (body string, status int, err error)

DoGet issues a GET and returns the response body, status, and any error, closing the response body before returning.

func FreePort

func FreePort(t *testing.T) int

FreePort asks the OS for an unused TCP port on 127.0.0.1. There's an inherent (tiny) race between releasing the probe port here and whatever binds it a few lines later, but this is the standard way to get an ephemeral port for a test.

func GetBodyWithRetry

func GetBodyWithRetry(t *testing.T, client *http.Client, url string) string

GetBodyWithRetry issues GET requests against url until one succeeds or the deadline passes. Caddy's listeners come up asynchronously, and the internal-TLS case also has to finish a synchronous certificate issuance during Provision, so a short retry loop here is standalone-test plumbing.

func LiveSmokeOnly

func LiveSmokeOnly() bool

LiveSmokeOnly reports whether this run is the PR smoke subset.

func OpenLiveStore

func OpenLiveStore(t *testing.T) *store.DB

OpenLiveStore opens a fresh SQLite store in a temp dir, closed on t.Cleanup.

func PersistReadyCondition

func PersistReadyCondition(ctx context.Context, t *testing.T, svcStore *store.DB, controllerName string, conditions []reconcile.Condition)

PersistReadyCondition writes conditions for controllerName directly, standing in for the production reconcile.Engine's own propagation. These tests drive application.Controller and ingress.Controller directly instead of through the Engine, so without this call the ingress controller's own readiness gate (F-002) never sees the application controller's Ready condition and refuses to route, exactly the failure this fix exists to prevent for a real unready deploy.

func ReconcileUntilAppReady

func ReconcileUntilAppReady(parent context.Context, ctrl *application.Controller, overallTimeout time.Duration) (reconcile.Result, error)

ReconcileUntilAppReady calls ctrl.Reconcile repeatedly until it reports a True Ready condition or overallTimeout elapses. A single Reconcile call isn't enough for a dependent service started right after its own dependency: depends_on only orders container start, it never waits for that dependency's own readiness (internal/compose's documented limitation), so a db-backed app can exit once on its first connection attempt and only recover on the next pass, the same resync shape reconcile.Engine applies in production.

func RequireFullLive

func RequireFullLive(t testing.TB)

RequireFullLive skips a heavy live suite in smoke runs. The skip message is what the CI job summary reports as skipped by design.

func SignHMAC

func SignHMAC(secret string, payload []byte) string

SignHMAC returns the hex-encoded HMAC-SHA256 of payload under secret, the signature shape every webhook provider under test here uses.

func WriteFile

func WriteFile(dir, name, content string) error

WriteFile writes content to dir/name with 0o600 permissions.

Types

type LiveBuildEnv

type LiveBuildEnv struct {
	DockerCli   *dockerclient.Client
	BuildClient *build.Client
	Runtime     docker.Runtime
}

LiveBuildEnv bundles the real Docker client, real BuildKit client, and real docker.Runtime every live test that builds an actual image needs, cleanly skipping the calling test if Docker or BuildKit aren't reachable.

func NewLiveBuildEnv

func NewLiveBuildEnv(t *testing.T) LiveBuildEnv

NewLiveBuildEnv returns a LiveBuildEnv, skipping t if Docker or BuildKit are not reachable.

Jump to

Keyboard shortcuts

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