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
- func AssertContainerAbsent(ctx context.Context, t *testing.T, runtime docker.Runtime, ...)
- func CleanupContainers(ctx context.Context, t *testing.T, rt docker.Runtime, serviceName string)
- func DoGet(client *http.Client, url string) (body string, status int, err error)
- func FreePort(t *testing.T) int
- func GetBodyWithRetry(t *testing.T, client *http.Client, url string) string
- func LiveSmokeOnly() bool
- func OpenLiveStore(t *testing.T) *store.DB
- func PersistReadyCondition(ctx context.Context, t *testing.T, svcStore *store.DB, controllerName string, ...)
- func ReconcileUntilAppReady(parent context.Context, ctrl *application.Controller, ...) (reconcile.Result, error)
- func RequireFullLive(t testing.TB)
- func SignHMAC(secret string, payload []byte) string
- func WriteFile(dir, name, content string) error
- type LiveBuildEnv
Constants ¶
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 ¶
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 ¶
DoGet issues a GET and returns the response body, status, and any error, closing the response body before returning.
func FreePort ¶
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 ¶
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 ¶
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 ¶
RequireFullLive skips a heavy live suite in smoke runs. The skip message is what the CI job summary reports as skipped by design.
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.