testutil

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package testutil provides test helpers for the Dockerfile linter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoViolations

func AssertNoViolations(tb testing.TB, violations []rules.Violation)

AssertNoViolations fails the test if there are any violations.

func AssertViolationCount

func AssertViolationCount(tb testing.TB, violations []rules.Violation, want int)

AssertViolationCount fails if the violation count doesn't match.

func GetSemantic

func GetSemantic(tb testing.TB, input rules.LintInput) *semantic.Model

GetSemantic extracts the *semantic.Model from a LintInput. Fails the test if the Semantic field is nil or not a *semantic.Model.

func MakeLintInput

func MakeLintInput(tb testing.TB, file, content string) rules.LintInput

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

func MakeLintInputWithConfig(tb testing.TB, file, content string, config any) rules.LintInput

MakeLintInputWithConfig creates a LintInput with rule configuration.

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.

Jump to

Keyboard shortcuts

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