Documentation
¶
Overview ¶
Package testsupport holds the helpers the tests of several packages share. Only _test.go files import it.
Index ¶
- Constants
- Variables
- func FirstDifferenceMessage(got, want string) string
- func FirstDifferentLine(a, b []byte) (int, string, string)
- func FirstMissingBlock(out string, blocks [][]string) string
- func ProblemStrings(problems []model.Problem) []string
- func ProblemStringsIn(dir string, problems []model.Problem) []string
- func ReadFile(t testing.TB, path string) []byte
- func ReplaceOrAppend[T any](list []T, item T, matches func(T) bool) []T
- func WriteFile(t testing.TB, path, text string)
- type Document
- type ExampleForm
Constants ¶
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>".
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 ¶
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: "portable/yaml", File: "proxyfile.yaml", Table: true}, {Dir: "portable/hocon", File: "Proxyfile", Table: true}, {Dir: "tracing/yaml", File: "proxyfile.yaml"}, {Dir: "tracing/hocon", File: "Proxyfile"}, {Dir: "tracing/envoy-tracing", File: "proxyfile.yaml", EnvoyBlock: true}, {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 FirstDifferenceMessage ¶ added in v2.2.0
FirstDifferenceMessage returns the first line where got and want differ, counted from 1, as one message for a test to print, or "" when they are equal. A text that ends first shows "" for that line. FirstDifferentLine does the same for bytes and returns the parts instead, for a test that words the message itself.
func FirstDifferentLine ¶ added in v2.2.0
FirstDifferentLine returns the number, counted from 1, of the line where a and b first differ, and that line of each, so a test of a generated file names the line to read instead of printing two whole files. The bytes before the first difference are the same in both, so the line starts at the same offset in each.
func FirstMissingBlock ¶ added in v2.2.0
FirstMissingBlock returns the first of blocks that out does not hold as whole lines, joined by newlines, or "" when it holds them all. The lines of a block follow one another with nothing between them, and each block comes after the one before it, so a test holds the order of the parts of a generated file as well as their text.
func ProblemStrings ¶
ProblemStrings returns each problem as the text a user reads, so a test compares problems with literal lines.
func ProblemStringsIn ¶
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 ReplaceOrAppend ¶ added in v2.2.0
ReplaceOrAppend returns a copy of list with item in place of the first item matches reports true for, or, when it reports true for none, with item appended. A test that declares a target of its own replaces the shipped one of that name this way, because a lookup by name finds the first.
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.
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
// EnvoyBlock says the form writes in the envoy block a key its example's YAML form writes at the top level, as
// tracing/envoy-tracing writes tracing in envoy.tracing, its old place. Envoy reads the two alike, but a render for
// another target leaves the envoy block alone by design, so the form is another spelling of the YAML form for the
// Envoy target only; for the others its own committed files hold it.
EnvoyBlock bool
}
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.