testsupport

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testsupport holds the helpers the tests of several packages share. Only _test.go files import it.

Index

Constants

View Source
const MinimalInlineOrigins = "origins:\n  all: {hosts: [localhost], origins: [\"http://localhost:3000\"]}\n"

MinimalInlineOrigins is the origins block of examples/minimal/yaml/proxyfile.yaml. The tests that need the file form, which no example writes, replace it with "origins: <file>".

View Source
const PartialMethods = "rpc:\n  methods:\n" +
	"    - {service: example.backend.v1.ReportService, method: ListReports, action: read, reports: [export, share]}\n"

PartialMethods is the rpc.methods block that, appended to examples/partial/yaml/proxyfile.yaml, writes in the proxyfile what examples/partial/methods.json lists, so a render that reads it must give that example's committed files.

Variables

View Source
var ExampleForms = []ExampleForm{
	{Dir: "minimal/yaml", File: "proxyfile.yaml"},
	{Dir: "minimal/hocon", File: "Proxyfile"},
	{Dir: "partial/yaml", File: "proxyfile.yaml", Methods: "../methods.json", Table: true},
	{Dir: "partial/hocon", File: "Proxyfile", Table: true},
	{Dir: "partial/proto-methods", File: "Proxyfile", Table: true},
	{Dir: "full/yaml", File: "proxyfile.yaml", Table: true},
	{Dir: "full/hocon", File: "Proxyfile", Table: true},
	{Dir: "tracing/yaml", File: "proxyfile.yaml"},
	{Dir: "tracing/hocon", File: "Proxyfile"},
	{Dir: "tracing/envoy-tracing", File: "proxyfile.yaml"},
	{Dir: "otel/yaml", File: "proxyfile.yaml"},
	{Dir: "otel/hocon", File: "Proxyfile"},
	{Dir: "jwt/yaml", File: "proxyfile.yaml"},
	{Dir: "jwt/hocon", File: "Proxyfile"},
	{Dir: "grpc/yaml", File: "proxyfile.yaml"},
	{Dir: "grpc/hocon", File: "Proxyfile"},
	{Dir: "balanced/yaml", File: "proxyfile.yaml"},
	{Dir: "balanced/hocon", File: "Proxyfile"},
	{Dir: "dns/yaml", File: "proxyfile.yaml"},
	{Dir: "dns/hocon", File: "Proxyfile"},
	{Dir: "tls/yaml", File: "proxyfile.yaml"},
	{Dir: "tls/hocon", File: "Proxyfile"},
	{Dir: "limited/yaml", File: "proxyfile.yaml"},
	{Dir: "limited/hocon", File: "Proxyfile"},
}

ExampleForms is every folder under examples/ that holds a proxyfile.

Functions

func ProblemStrings

func ProblemStrings(problems []model.Problem) []string

ProblemStrings returns each problem as the text a user reads, so a test compares problems with literal lines.

func ProblemStringsIn

func ProblemStringsIn(dir string, problems []model.Problem) []string

ProblemStringsIn is ProblemStrings with dir taken off the front of each line, so a row names a file written to a temporary directory by its base name alone. A line naming a file elsewhere is kept whole.

func ReadFile

func ReadFile(t testing.TB, path string) []byte

ReadFile returns the bytes of the file at path, ending the test when it cannot.

func WriteFile

func WriteFile(t testing.TB, path, text string)

WriteFile writes text to the file at path, ending the test when it cannot.

Types

type Document

type Document []string

Document is a valid file kept one line per item, so that each test row changes it by line number and the row's expected positions can be counted from the change alone.

func (Document) Inserted

func (d Document) Inserted(at int, line string) string

Inserted returns the document with line put in as line number at.

func (Document) Replaced

func (d Document) Replaced(first, last int, lines ...string) string

Replaced returns the document with its lines first to last, counted from 1, replaced by lines.

func (Document) String

func (d Document) String() string

type ExampleForm added in v2.1.0

type ExampleForm struct {
	Dir  string // under examples/, as <example>/<form>
	File string // the proxyfile in Dir, under a name render and check read when given no file
	// Methods is the --rpc-methods file the form is rendered with, relative to Dir, or "" when the proxyfile writes
	// its methods or has no rpc entry.
	Methods string
	Table   bool // Dir holds rpc-table.json, the table the form's RPC methods give
}

ExampleForm is one folder under examples/ that holds a proxyfile. Each example writes one gateway in more than one form, each form in a folder of its own, because render and check read a default file only when the folder holds one. The folder also holds the envoy.yaml the proxyfile renders, and rpc-table.json where the example has a table.

Jump to

Keyboard shortcuts

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