Documentation ¶
Overview ¶
Package helper contains implementations for plugin testing.
You can test the implemented rules using the mock Runner that is not an RPC 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 AssertIssues(t *testing.T, expected Issues, actual Issues)
- func AssertIssuesWithoutRange(t *testing.T, expected Issues, actual Issues)
- type Config
- type Issue
- type Issues
- type RuleConfig
- type Runner
- func (r *Runner) Backend() (*configs.Backend, error)
- func (r *Runner) Config() (*configs.Config, error)
- 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) EmitIssueOnExpr(rule tflint.Rule, message string, expr hcl.Expression) error
- func (r *Runner) EnsureNoError(err error, proc func() error) error
- func (r *Runner) EvaluateExpr(expr hcl.Expression, ret interface{}, wantTy *cty.Type) error
- func (r *Runner) EvaluateExprOnRootCtx(expr hcl.Expression, ret interface{}, wantType *cty.Type) error
- func (r *Runner) File(filename string) (*hcl.File, error)
- func (r *Runner) IsNullExpr(expr hcl.Expression) (bool, error)
- func (r *Runner) RootProvider(name string) (*configs.Provider, error)
- func (r *Runner) WalkModuleCalls(walker func(*configs.ModuleCall) error) error
- func (r *Runner) WalkResourceAttributes(resourceType, attributeName string, walker func(*hcl.Attribute) error) error
- func (r *Runner) WalkResourceBlocks(resourceType, blockType string, walker func(*hcl.Block) error) error
- func (r *Runner) WalkResources(resourceType string, walker func(*configs.Resource) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertIssues ¶
AssertIssues is an assertion helper for comparing issues.
Types ¶
type Config ¶
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 ¶
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 { Files map[string]*hcl.File 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 ¶
DecodeRuleConfig extracts the rule's configuration into the given value
func (*Runner) EmitIssueOnExpr ¶
EmitIssueOnExpr adds an issue to the runner itself.
func (*Runner) EnsureNoError ¶
EnsureNoError is a method that simply runs a function if there is no error.
func (*Runner) EvaluateExpr ¶
EvaluateExpr returns a value of the passed expression. Note that some features are limited
func (*Runner) EvaluateExprOnRootCtx ¶
func (r *Runner) EvaluateExprOnRootCtx(expr hcl.Expression, ret interface{}, wantType *cty.Type) error
EvaluateExprOnRootCtx returns a value of the passed expression. Note this is just alias of EvaluateExpr.
func (*Runner) IsNullExpr ¶
IsNullExpr checks whether the passed expression is null or not. Note that it does not eval the expression for simplify the implementation.
func (*Runner) RootProvider ¶
RootProvider returns the provider configuration. In the helper runner, it always returns its own provider.
func (*Runner) WalkModuleCalls ¶
func (r *Runner) WalkModuleCalls(walker func(*configs.ModuleCall) error) error
WalkModuleCalls visits all module calls from Files.
func (*Runner) WalkResourceAttributes ¶
func (r *Runner) WalkResourceAttributes(resourceType, attributeName string, walker func(*hcl.Attribute) error) error
WalkResourceAttributes visits all specified attributes from Files.