telemetrygolang.org/x/telemetry/internal/regtest Index | Files

package regtest

import "golang.org/x/telemetry/internal/regtest"

Package regtest provides helpers for end-to-end testing involving counter and upload packages.

Index

Functions

func CreateTestUploadConfig

func CreateTestUploadConfig(t *testing.T, counterNames, stackCounterNames []string) *telemetry.UploadConfig

CreateTestUploadConfig creates a new upload config for the current program, permitting the given counters.

func ProgramInfo

func ProgramInfo(t *testing.T) (goVersion, progPath, progVersion string)

ProgramInfo returns the go version, program name and version info the process would record in its counter file.

func RunProg

func RunProg(t *testing.T, telemetryDir string, prog Program) ([]byte, error)

RunProg runs the program prog in a separate process with the specified telemetry directory. RunProg can be called multiple times in the same test, but all the programs must be registered with NewProgram before the first call to RunProg.

func RunProgAsOf

func RunProgAsOf(t *testing.T, telemetryDir string, asof time.Time, prog Program) ([]byte, error)

RunProgAsOf is like RunProg, but executes the program as of a specific counter time.

Types

type Program

type Program string

Program is a value that can be used to identify a program in the test.

func NewIncProgram

func NewIncProgram(t *testing.T, name string, counters ...string) Program

NewIncProgram returns a basic program that increments the given counters and exits with status 0.

func NewProgram

func NewProgram(t *testing.T, name string, fn func() int) Program

NewProgram returns a Program value that can be used to identify a program to run by RunProg. The program must be registered with NewProgram before the first call to RunProg in the test function.

RunProg runs this binary in a separate process with special environment variables that specify the entry point. When this binary runs with the environment variables that match the specified name, NewProgram calls the given fn and exits with the return value. Note that all the code before NewProgram is executed in both the main process and the subprocess.

Source Files

regtest.go

Version
v0.0.0-20250214215356-6f9b61db478c (latest)
Published
Feb 14, 2025
Platform
linux/amd64
Imports
13 packages
Last checked
3 days ago

Tools for package owners.