Documentation
¶
Overview ¶
Package testguard provides test isolation primitives that prevent ox subprocesses from hitting production endpoints during tests.
All test code that runs ox as a subprocess MUST use RunOx or OxCmd instead of exec.Command + os.Environ(). This ensures:
- minimal environment (no leaked auth, daemon sockets, or SAGEOX_ENDPOINT)
- OX_NO_DAEMON=1 always injected
- production hostnames in env values cause immediate test failure
- mock server responses are validated for production URL leaks
Index ¶
- func BuildOxBinary(t *testing.T, projectRoot string) string
- func MinimalEnv(testVars []string) []string
- func OxCmd(t *testing.T, oxBin, dir string, envVars []string, args ...string) *exec.Cmd
- func OxCmdContext(t *testing.T, ctx context.Context, oxBin, dir string, envVars []string, ...) *exec.Cmd
- func RunOx(t *testing.T, oxBin, dir string, envVars []string, args ...string) (string, int, time.Duration)
- func StopDaemonCleanup(t *testing.T, oxBin, repoDir string, envVars []string)
- type MockServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildOxBinary ¶
BuildOxBinary compiles the ox binary and returns its path. This is the one place where os.Environ() is acceptable (go build only).
func MinimalEnv ¶
MinimalEnv builds a clean environment from the allowlist + caller overrides. Always injects OX_NO_DAEMON=1.
func OxCmdContext ¶
func OxCmdContext(t *testing.T, ctx context.Context, oxBin, dir string, envVars []string, args ...string) *exec.Cmd
OxCmdContext builds an isolated exec.Cmd with an explicit context. Validates that no env value contains production hostnames.
Types ¶
type MockServer ¶
MockServer is an alias for httptest.Server, returned by SafeMockServer.
func SafeMockServer ¶
func SafeMockServer(t *testing.T, handler http.Handler) *MockServer
SafeMockServer wraps an http.Handler to validate that response bodies never contain production URLs. If detected, the test fails immediately.