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 ¶
- func AssertChanges(t *testing.T, want map[string]string, got map[string][]byte)
- func AssertIssues(t *testing.T, want Issues, got Issues)
- func AssertIssuesWithoutRange(t *testing.T, want Issues, got Issues)
- type Config
- type Issue
- type Issues
- type RuleConfig
- type Runner
- func (r *Runner) Changes() map[string][]byte
- func (r *Runner) DecodeRuleConfig(name string, ret interface{}) error
- func (r *Runner) EmitIssue(rule tflint.Rule, message string, location hcl.Range) error
- func (r *Runner) EmitIssueWithFix(rule tflint.Rule, message string, location hcl.Range, ...) error
- func (r *Runner) EnsureNoError(err error, proc func() error) errordeprecated
- func (r *Runner) EvaluateExpr(expr hcl.Expression, target interface{}, opts *tflint.EvaluateExprOption) error
- func (r *Runner) GetFile(filename string) (*hcl.File, error)
- func (r *Runner) GetFiles() (map[string]*hcl.File, error)
- func (r *Runner) GetModuleContent(schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (r *Runner) GetModulePath() (addrs.Module, error)
- func (r *Runner) GetOriginalwd() (string, error)
- func (r *Runner) GetProviderContent(name string, schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (r *Runner) GetResourceContent(name string, schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (r *Runner) WalkExpressions(walker tflint.ExprWalker) hcl.Diagnostics
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertChanges ¶ added in v0.17.0
AssertChanges is an assertion helper for comparing autofix changes.
func AssertIssues ¶
AssertIssues is an assertion helper for comparing issues.
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 ¶
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 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 ¶
TestRunner returns a mock Runner for testing. You can pass the map of file names and their contents in the second argument.
func (*Runner) DecodeRuleConfig ¶ added in v0.7.0
DecodeRuleConfig extracts the rule's configuration into the given value
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 (*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) 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
GetModulePath always returns the root module path address
func (*Runner) GetOriginalwd ¶ added in v0.15.0
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.