Documentation
¶
Overview ¶
Package testutil provides test helpers for the Dockerfile linter.
Index ¶
- func AssertNoViolations(tb testing.TB, violations []rules.Violation)
- func AssertViolationCount(tb testing.TB, violations []rules.Violation, want int)
- func GetSemantic(tb testing.TB, input rules.LintInput) *semantic.Model
- func MakeLintInput(tb testing.TB, file, content string) rules.LintInput
- func MakeLintInputWithConfig(tb testing.TB, file, content string, config any) rules.LintInput
- func MakeLintInputWithContext(tb testing.TB, file, content string, buildContext facts.ContextFileReader) rules.LintInput
- func ParseDockerfile(tb testing.TB, content string) *dockerfile.ParseResult
- func RunRuleTests(t *testing.T, rule rules.Rule, cases []RuleTestCase)
- type RuleTestCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertNoViolations ¶
AssertNoViolations fails the test if there are any violations.
func AssertViolationCount ¶
AssertViolationCount fails if the violation count doesn't match.
func GetSemantic ¶
GetSemantic extracts the *semantic.Model from a LintInput. Fails the test if the Semantic field is nil.
func MakeLintInput ¶
MakeLintInput creates a LintInput for testing a rule. Parses the Dockerfile content and constructs the input struct with full BuildKit instruction parsing including Stages, MetaArgs, and semantic model.
func MakeLintInputWithConfig ¶
MakeLintInputWithConfig creates a LintInput with rule configuration.
func MakeLintInputWithContext ¶ added in v0.31.0
func MakeLintInputWithContext( tb testing.TB, file, content string, buildContext facts.ContextFileReader, ) rules.LintInput
MakeLintInputWithContext creates a LintInput for testing a rule with build context.
func ParseDockerfile ¶
func ParseDockerfile(tb testing.TB, content string) *dockerfile.ParseResult
ParseDockerfile parses a Dockerfile from a string using the full parsing pipeline. Returns the complete ParseResult including AST, Stages, MetaArgs, and Warnings.
Use this when you need the full parsed result (e.g., testing parser features). For rule testing, prefer MakeLintInput which creates a ready-to-use LintInput.
func RunRuleTests ¶
func RunRuleTests(t *testing.T, rule rules.Rule, cases []RuleTestCase)
RunRuleTests runs a table of test cases against a rule.
Types ¶
type RuleTestCase ¶
type RuleTestCase struct {
// Name is the test case name.
Name string
// Content is the Dockerfile content to lint.
Content string
// Config is the optional rule configuration.
Config any
// WantViolations is the expected number of violations.
// Use -1 to skip the count check.
WantViolations int
// WantCodes is the expected rule codes in violation order (for detailed checks).
WantCodes []string
// WantMessages are substrings expected in violation messages.
WantMessages []string
}
RuleTestCase defines a test case for table-driven rule tests.