testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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 GetBuf

func GetBuf(t *testing.T, version string) string

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

func RequireEnvToken(t *testing.T, envVar string) string

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_GITHUB_TOKEN.

func RunBufDepUpdate

func RunBufDepUpdate(t *testing.T, bufBinary string, port int) (int, string)

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.

func RunBufModUpdate

func RunBufModUpdate(t *testing.T, bufBinary string, port int) (int, string)

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.

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.

Jump to

Keyboard shortcuts

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