helper

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIssues

func AssertIssues(t *testing.T, expected Issues, actual Issues)

AssertIssues is an assertion helper for comparing issues.

func AssertIssuesWithoutRange

func AssertIssuesWithoutRange(t *testing.T, expected Issues, actual Issues)

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

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

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

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

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) Backend

func (r *Runner) Backend() (*configs.Backend, error)

Backend returns the terraform backend configuration.

func (*Runner) Config

func (r *Runner) Config() (*configs.Config, error)

Config returns the Terraform configuration

func (*Runner) DecodeRuleConfig

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) EmitIssueOnExpr

func (r *Runner) EmitIssueOnExpr(rule tflint.Rule, message string, expr hcl.Expression) error

EmitIssueOnExpr adds an issue to the runner itself.

func (*Runner) EnsureNoError

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

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

func (*Runner) EvaluateExpr

func (r *Runner) EvaluateExpr(expr hcl.Expression, ret interface{}, wantTy *cty.Type) error

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) File

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

File returns the hcl.File object

func (*Runner) IsNullExpr

func (r *Runner) IsNullExpr(expr hcl.Expression) (bool, error)

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

func (r *Runner) RootProvider(name string) (*configs.Provider, error)

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.

func (*Runner) WalkResourceBlocks

func (r *Runner) WalkResourceBlocks(resourceType, blockType string, walker func(*hcl.Block) error) error

WalkResourceBlocks visits all specified blocks from Files.

func (*Runner) WalkResources

func (r *Runner) WalkResources(resourceType string, walker func(*configs.Resource) error) error

WalkResources visits all specified resources from Files.

Jump to

Keyboard shortcuts

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