helper

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MPL-2.0 Imports: 19 Imported by: 4

Documentation

Overview

Package helper contains implementations for plugin testing.

You can test the implemented rules using the mock Runner that is not an gRPC client. It is similar to TFLint's Runner, but is implemented from scratch to avoid Terraform dependencies.

Some implementations of the mock Runner have been simplified. As a result, note that some features may not behave exactly as they should.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertChanges added in v0.17.0

func AssertChanges(t *testing.T, want map[string]string, got map[string][]byte)

AssertChanges is an assertion helper for comparing autofix changes.

func AssertIssues

func AssertIssues(t *testing.T, want Issues, got Issues)

AssertIssues is an assertion helper for comparing issues.

func AssertIssuesWithoutRange

func AssertIssuesWithoutRange(t *testing.T, want Issues, got Issues)

AssertIssuesWithoutRange is an assertion helper for comparing issues except for range.

Types

type Config added in v0.7.0

type Config struct {
	Rules []RuleConfig `hcl:"rule,block"`
}

Config is a pseudo TFLint config file object for testing from plugins.

type Issue

type Issue struct {
	Rule    tflint.Rule
	Message string
	Range   hcl.Range
}

Issue is a stub that has the same structure as the actually used issue object. This is only used for testing, as the mock Runner doesn't depend on the actual Issue structure.

type Issues

type Issues []*Issue

Issues is a list of Issue.

type RuleConfig added in v0.7.0

type RuleConfig struct {
	Name    string   `hcl:"name,label"`
	Enabled bool     `hcl:"enabled"`
	Body    hcl.Body `hcl:",remain"`
}

RuleConfig is a pseudo TFLint config file object for testing from plugins.

type Runner

type Runner struct {
	Issues Issues
	// contains filtered or unexported fields
}

Runner is a mock that satisfies the Runner interface for plugin testing.

func TestRunner

func TestRunner(t *testing.T, files map[string]string) *Runner

TestRunner returns a mock Runner for testing. You can pass the map of file names and their contents in the second argument.

func (*Runner) Changes added in v0.17.0

func (r *Runner) Changes() map[string][]byte

Changes returns formatted changes by the fixer.

func (*Runner) DecodeRuleConfig added in v0.7.0

func (r *Runner) DecodeRuleConfig(name string, ret interface{}) error

DecodeRuleConfig extracts the rule's configuration into the given value

func (*Runner) EmitIssue

func (r *Runner) EmitIssue(rule tflint.Rule, message string, location hcl.Range) error

EmitIssue adds an issue to the runner itself.

func (*Runner) EmitIssueWithFix added in v0.17.0

func (r *Runner) EmitIssueWithFix(rule tflint.Rule, message string, location hcl.Range, fixFunc func(f tflint.Fixer) error) error

EmitIssueWithFix adds an issue and invoke fix.

func (*Runner) EnsureNoError deprecated

func (r *Runner) EnsureNoError(err error, proc func() error) error

EnsureNoError is a method that simply runs a function if there is no error.

Deprecated: Use EvaluateExpr with a function callback. e.g. EvaluateExpr(expr, func (val T) error {}, ...)

func (*Runner) EvaluateExpr

func (r *Runner) EvaluateExpr(expr hcl.Expression, target interface{}, opts *tflint.EvaluateExprOption) error

EvaluateExpr returns a value of the passed expression. Note that some features are limited

func (*Runner) GetFile added in v0.10.0

func (r *Runner) GetFile(filename string) (*hcl.File, error)

GetFile returns the hcl.File object

func (*Runner) GetFiles added in v0.10.0

func (r *Runner) GetFiles() (map[string]*hcl.File, error)

GetFiles returns all hcl.File

func (*Runner) GetModuleContent added in v0.10.0

func (r *Runner) GetModuleContent(schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetModuleContent gets a content of the current module

func (*Runner) GetModulePath added in v0.12.0

func (r *Runner) GetModulePath() (addrs.Module, error)

GetModulePath always returns the root module path address

func (*Runner) GetOriginalwd added in v0.15.0

func (r *Runner) GetOriginalwd() (string, error)

GetOriginalwd always returns the current directory

func (*Runner) GetProviderContent added in v0.12.0

func (r *Runner) GetProviderContent(name string, schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetProviderContent gets a provider content of the current module

func (*Runner) GetResourceContent added in v0.10.0

func (r *Runner) GetResourceContent(name string, schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetResourceContent gets a resource content of the current module

func (*Runner) WalkExpressions added in v0.12.0

func (r *Runner) WalkExpressions(walker tflint.ExprWalker) hcl.Diagnostics

WalkExpressions traverses expressions in all files by the passed walker.

type Variable added in v0.10.0

type Variable struct {
	Name      string
	Default   cty.Value
	DeclRange hcl.Range
}

Variable is an implementation of variables in Terraform language

Jump to

Keyboard shortcuts

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