Documentation
¶
Overview ¶
Package e2e provides an end-to-end testing framework for dmt.
Cases are organized as testdata/<linter>/<case>/, grouping each case under the linter it primarily exercises. A case directory contains:
- expected.yaml: the case specification (description + expected findings).
- a module subdirectory (default "module/") that is linted as if the user ran `dmt lint <module>`.
A case is executed by copying its module into an isolated temp directory and running the full lint manager against it, then matching the structured findings against the expectations declared in expected.yaml. This exercises the real lint pipeline (config loading, helm render, every linter) rather than a single rule in isolation, while still letting each case assert on concrete, human-readable outcomes.
A case may instead set "kind: conversions" to run the `dmt test conversions` testers; those results are adapted into the same finding shape (linter ID "conversions") so the same expectation matching applies.
Index ¶
Constants ¶
const ( KindLint = "lint" KindConversions = "conversions" )
Case kinds. A case either lints a module (KindLint, the default) or runs the `dmt test conversions` testers against it (KindConversions).
Variables ¶
This section is empty.
Functions ¶
func Lint ¶
func Lint(moduleDir string) ([]pkg.LinterError, error)
Lint runs the dmt lint pipeline against a module directory and returns all findings. The module is copied into an isolated temp directory first so the run is hermetic (no config inherited from parent dirs, no artifacts written back into testdata).
func Run ¶
func Run(kind, moduleDir string) ([]pkg.LinterError, error)
Run executes a case (lint or conversions) against a module directory and returns the produced findings.
func RunConversions ¶
func RunConversions(moduleDir string) ([]pkg.LinterError, error)
RunConversions runs the `dmt test conversions` testers against a module directory and returns the results adapted to the common finding shape (LinterID "conversions", ObjectID set to the test name).
Types ¶
type CaseSpec ¶
type CaseSpec struct {
// Description is a human-readable summary of what the case verifies.
Description string `yaml:"description"`
// Kind selects what to run against the module: "lint" (default) runs the
// full lint pipeline, "conversions" runs the `dmt test conversions` testers.
// For conversions cases, findings are exposed with linter ID "conversions"
// and ObjectID set to the test name, so the same expectations apply.
Kind string `yaml:"kind"`
// Module is the subdirectory (relative to the case dir) that gets linted.
// Defaults to "module".
Module string `yaml:"module"`
// ExpectClean asserts that the lint produced zero findings.
ExpectClean bool `yaml:"expectClean"`
// Expect lists the findings that must be present.
Expect []Finding `yaml:"expect"`
// Exhaustive, when true, asserts that there are no findings beyond those
// listed in Expect (every produced finding must be matched by some Finding).
Exhaustive bool `yaml:"exhaustive"`
}
CaseSpec is the schema of an expected.yaml file.
func LoadCaseSpec ¶
LoadCaseSpec reads and parses the expected.yaml file from a case directory.
type Finding ¶
type Finding struct {
Linter string `yaml:"linter"`
Rule string `yaml:"rule"`
Level string `yaml:"level"`
TextContains string `yaml:"textContains"`
Count int `yaml:"count"`
}
Finding declares one expected lint finding for a case.
Matching semantics:
- linter is required and matched case-insensitively against LinterID.
- rule, level and textContains are optional; when set they all must match.
- textContains is a case-sensitive substring match against the message.
- count is the expected number of matching findings; 0 means "at least one".
type MatchResult ¶
type MatchResult struct {
// Failures contains human-readable descriptions of unmet expectations.
Failures []string
}
MatchResult describes the outcome of matching findings against expectations.
func Match ¶
func Match(spec *CaseSpec, findings []pkg.LinterError) MatchResult
Match compares the produced findings against a case spec.
func (MatchResult) OK ¶
func (r MatchResult) OK() bool
OK reports whether every expectation was satisfied.