Documentation
¶
Overview ¶
Package testutil provides reusable test helpers for E2E proxy tests.
It extracts the inline test infrastructure from e2e/smoke_test.go into a proper, importable package for use by Phases 4 and 5 integration tests.
Index ¶
- Constants
- func AvailableBufVersions(t *testing.T) []string
- func GetBuf(t *testing.T, version string) string
- func RequireEnvToken(t *testing.T, envVar string) string
- func RunBufDepUpdate(t *testing.T, bufBinary string, port int) (int, string)
- func RunBufDepUpdateWithRef(t *testing.T, bufBinary string, port int, ref string) (int, string, []byte)
- func RunBufGenerateWithPinnedLock(t *testing.T, bufBinary string, port int, pinnedCommit string) (int, string, []string)
- func RunBufModUpdate(t *testing.T, bufBinary string, port int) (int, string)
- func RunBufModUpdateWithRef(t *testing.T, bufBinary string, port int, ref string) (int, string, []byte)
- type ServerResult
- type TestConfig
Constants ¶
const ( // BufV130 is the last buf version supporting the deprecated registry.v1alpha1 protocol. BufV130 = "v1.30.1" // BufV169 is a modern buf version using the current protocol. BufV169 = "v1.69.0" )
Pinned buf binary versions for testing.
Variables ¶
This section is empty.
Functions ¶
func AvailableBufVersions ¶ added in v0.3.7
AvailableBufVersions returns the list of buf version strings that have a cached binary on disk under testdata/buf/. The list is discovered dynamically (one directory per version) so that adding a new version to the cache is enough to extend the matrix of E2E tests. Order is the natural directory sort (lexicographic), which puts older versions first.
Returns an empty slice (without failing the test) when testdata/buf does not exist. This is the common case on CI, where the cached binaries are gitignored: callers should treat len(versions)==0 as "no binaries to test against" and t.Skip() rather than fataling. The directory being unreadable for a different reason (permission denied, etc.) is still a hard error.
func GetBuf ¶
GetBuf returns the path to a pinned buf binary, downloading it from GitHub Releases on cache miss. Binaries are cached at testdata/buf/{version}/buf.
Checksum verification is intentionally skipped: the download uses HTTPS from GitHub's CDN which provides transport integrity. The binaries are used only in tests, not in production.
func RequireEnvToken ¶
RequireEnvToken reads an environment variable and skips the test if it is empty. Returns the token value. Use this for required test secrets like EASYP_GH_TOKEN (current) or EASYP_GITHUB_TOKEN (legacy).
func RunBufDepUpdate ¶
RunBufDepUpdate creates a minimal buf module in a temp directory and runs "buf dep update" against the proxy at the given port. Returns the exit code and stderr output. This is exported for use by Phase 5 tests.
The dep reference is "<host>:<port>/googleapis/googleapis" (no ref) so the proxy falls back to HEAD. To exercise the Name.ref code path, use RunBufDepUpdateWithRef instead.
func RunBufDepUpdateWithRef ¶ added in v0.3.10
func RunBufDepUpdateWithRef(t *testing.T, bufBinary string, port int, ref string) (int, string, []byte)
RunBufDepUpdateWithRef is the ref-pinned variant of RunBufDepUpdate. Same contract as RunBufModUpdateWithRef but invokes "buf dep update". Only buf v1.32+ understands "buf dep update"; older binaries must use RunBufModUpdateWithRef.
func RunBufGenerateWithPinnedLock ¶ added in v0.3.10
func RunBufGenerateWithPinnedLock(t *testing.T, bufBinary string, port int, pinnedCommit string) (int, string, []string)
RunBufGenerateWithPinnedLock creates a minimal buf module in a temp directory, runs "buf mod update" against the proxy at the given port, overwrites the resulting buf.lock's commit: line with pinnedCommit (a 32-char dashless buf-issued UUID), and then runs "buf generate" against the overwritten lock. Returns the exit code of "buf generate", the stderr it produced, and the list of generated gen/go/google/type/*.pb.go files on success (nil on failure).
The temp workspace contains:
- buf.yaml: deps: [127.0.0.1:<port>/googleapis/googleapis]
- dummy.proto: syntax = "proto3"; package dummy;
- buf.gen.yaml: pinned remote plugin buf.build/protocolbuffers/go:v1.28.1 with out: gen/go
This exercises the read-path that fires AFTER the client has loaded buf.lock: the proxy must resolve a pre-existing 32-char UUID via its infoCache/commitMap or the post-restart probeCommitID path, and return content for that commit (NOT HEAD, NOT a 400 on a "foreign" id).
func RunBufModUpdate ¶
RunBufModUpdate creates a minimal buf module in a temp directory and runs "buf mod update" against the proxy at the given port. Returns the exit code and stderr output. This is exported for use by Phase 4 and 5 tests.
The dep reference is "<host>:<port>/googleapis/googleapis" (no ref) so the proxy falls back to HEAD. To exercise the Name.ref code path, use RunBufModUpdateWithRef instead.
func RunBufModUpdateWithRef ¶ added in v0.3.10
func RunBufModUpdateWithRef(t *testing.T, bufBinary string, port int, ref string) (int, string, []byte)
RunBufModUpdateWithRef is the ref-pinned variant of RunBufModUpdate. It writes a buf.yaml whose dep reference ends with ":ref" so the buf CLI sends the ref in the Name.ref field. Returns the exit code, stderr, and the contents of buf.lock on success (nil on failure).
Use this to verify the proxy honors Name.ref end-to-end: the lock file produced by a ref-pinned update should pin to the SHA at that ref, not to HEAD.
Types ¶
type ServerResult ¶
type ServerResult struct {
// Port is the allocated TCP port number the server is listening on.
Port int
// Output contains the combined stdout/stderr output from the server subprocess.
// Use this in test failure messages for diagnostics.
Output *bytes.Buffer
}
ServerResult holds the result of starting a test proxy server.
func StartServer ¶
func StartServer(t *testing.T, cfg TestConfig) ServerResult
StartServer starts the TLS proxy as a subprocess, waits for it to accept TCP connections, and registers cleanup via t.Cleanup. Returns a ServerResult with the allocated port and a buffer capturing server output.
The server is started via "go run ./cmd/easyp -cfg <path>" with a config generated from cfg. The subprocess runs in the project root directory. Tests that call StartServer should first call RequireEnvToken to ensure the GitHub token is available.
type TestConfig ¶
type TestConfig struct {
// TLSCertPath is the path to the TLS certificate file.
TLSCertPath string
// TLSKeyPath is the path to the TLS private key file.
TLSKeyPath string
// GithubToken is the GitHub API token for authenticating requests.
GithubToken string
// RepoOwner is the GitHub repository owner (e.g., "googleapis").
RepoOwner string
// RepoName is the GitHub repository name (e.g., "googleapis").
RepoName string
// RepoPaths is the list of proto paths to serve from the repository.
RepoPaths []string
// LogLevel is the proxy log level. Defaults to "info" if empty.
LogLevel string
}
TestConfig holds the configuration for starting a test proxy server.
func DefaultTestConfig ¶
func DefaultTestConfig() TestConfig
DefaultTestConfig returns a TestConfig populated from environment variables and sensible defaults. Tests should call RequireEnvToken to ensure the GitHub token is present before using this config with StartServer.